Determine the container class of an object in Python 3

qrious mittra at juno.com
Wed Oct 25 21:25:39 EDT 2017


Class1 is instantiated in Class2 as follows. Class2 also contains another variable, say:

class Class2: 
    class1 = Class1()
    a = 0

I want to create a method myDef() in Class1 that can read or write to a. How do I access a from within myDef() to access a?

Calling Class2.a is not an option as Class1 does not have any knowledge about its container class a priori. Also, this will hardcode the path. I want to know of a built-in method (kind of equivalent of super() for inheritance) that will give me the container class reference, Class2 in this case. 

Thanks. 



More information about the Python-list mailing list