所以,我试图得到一个自定义对象在'内部'的对象.这是一个例子.
假设o是一个对象 - 它不管是什么类型,它只能存储变量.
o = Object()
class Test():
def __init__(self):
self.parent = o ## This is where I fall off; I want to be able to access
## the o object from within the Test object
o.test = Test()
Run Code Online (Sandbox Code Playgroud)
那么,我如何从Test内部获得o?我知道我可以编写Test函数来传递它
o.test = Test(o)
Run Code Online (Sandbox Code Playgroud)
但我宁愿从类定义中做到这一点.