Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

How to access parent class object through derived class instance?

$
0
0

Let's suppose I have these classes:

class A():    msg = 'hehehe'class B(A):    msg = 'hohoho'class C(B):    pass

and an instance of B or C. How do I get the variable msg from the parent's class object through this instance?

I've tried this:

foo = B()print super(foo.__class__).msg

but got the message:

TypeError: super() argument 1 must be type, not classobj


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>