[英]Accessing class from variable within class
For example:例如:
class Foo:
def __init__(self):
self.bar = []
class Baz():
pass
test = Foo()
test.bar.append(
Baz()
)
Now that I have instantiated Baz
, how can I access test
from Baz
?现在我已经实例化了
Baz
,我如何从Baz
访问test
?
You would need to give each Baz
a reference to test
if you wanted things to be set up like this:如果你想像这样设置事情,你需要给每个
Baz
一个参考来test
:
class Baz():
def __init__(self, test):
self.test = test
test = Foo()
test.bar.append(
Baz(test)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.