Hello everyone!
I'd like to know if there's a way to access to the class (or its fields) where an object is instantiated. Let's say I have:
def Class1:
def __init__(self):
self.title = "randomTitle"
self.anotherField = float()
self.class2Field = Class2()
and the class whose type will be the class2Field
:
def Class2:
def __init__(self):
self.field1 = ""
self.field2 = ""
# . . . #
I'd like to know if there's a way to access the instance of Class1 from the instance of Class2
that is declared in Class1
(meaning, accessing the fields of Class1
from the variable self.class2Field
in that Class1
instance)
I know I can always change the __init__
in Class2 to accept a Class1
parameter, but I'd like to know if there's another way of "climbing" through the class hierarchy.
Thank you very much!