相关疑难解决方法(0)

从python中获取容器/父对象

在Python中,是否有可能从Bar本身获取包含另一个对象Bar的对象,比如说Foo?这是我的意思的一个例子

class Foo(object):
    def __init__(self):
        self.bar = Bar()
        self.text = "Hello World"

class Bar(object):
    def __init__(self):
        self.newText = foo.text #This is what I want to do, 
                                #access the properties of the container object

foo = Foo()
Run Code Online (Sandbox Code Playgroud)

这可能吗?谢谢!

python containers class object

28
推荐指数
2
解决办法
2万
查看次数

标签 统计

class ×1

containers ×1

object ×1

python ×1