python - How to invoke __repr__ of parent class? -
So the situation I want to solve is very simple to assume that I have a subclass C
Which increases parents B
and A
. Parents b
, and a
each have their own __ repr __
methods. When I print out C
, the method of parent a
is always applicable, but I always use the parent < Code> B
How can I do this?
"post-text" itemprop = "text">
Assume that A
is defined as:
class A ( ): Def __repr __ (self): Return is defined as "this one is"
and b
is similarly defined:
Class B (): def __repr __ (self): return is "it is b" while is defined as c
:
class C (A, B): def __init __ (self): pass
or something similar. This will generate a from print A ()
, while for the B
the same will generate this b
. will print C ()
, as you describe, give this one is
. However, if you only change the succession of C
:
class C (B, A): A and B def change order __init __ (self): Pass
then print C ()
will give you this B
. Simple as that.
Comments
Post a Comment