- Jul 19, 2006
- 1,151
- 0
- 0
I am wondering if there is a way to get whatever class created the instance.
Example:
EDIT: Most likely I'll have to pass self on. EX: self.x = Class2('Woo!', self).
Was just wondering if there was another way.
Example:
How do I derive the class instance (or name) that created the x instance? In other words, if I was given the instance x, how do I get the name 'class1'. Using x.__class__.__name__ will obviously only give you the Class2 name. Is this even possible? Thanks.class Class1:
def __init__(self):
self.x = Class2('Woo!')
class Class2:
def __init__(self, word):
print word
meow = Class1()
EDIT: Most likely I'll have to pass self on. EX: self.x = Class2('Woo!', self).
Was just wondering if there was another way.
