我想B類是象類A的孩子:如何在python中爲另一個類定義一個包含類?
class A(object):
def __init__(self, id):
self.id = id
b1 = B()
b2 = B()
self.games_summary_dicts = [b1, b2]
""":type : list[B]"""
class B(object):
def __init__(self):
...
def do_something_with_containing_class(self):
"""
Doing something with self.id of A class. Something like 'self.container.id'
"""
...
我想b1的「do_something_with_containing_class」真正做一些事來A的實例,它是下的,所以如果它改變的東西,它會也可用於b2。
是否有類或語法?
工作正常!我忘記了那些對象是通過引用而不是按值傳遞的,所以它正是我所需要的。謝謝! –