python - 从类中的变量访问类
问题描述
例如:
class Foo:
def __init__(self):
self.bar = []
class Baz():
pass
test = Foo()
test.bar.append(
Baz()
)
现在我已经实例化Baz
了,我该如何test
访问Baz
?
解决方案
如果您希望像这样设置事物,则需要给每个Baz
参考:test
class Baz():
def __init__(self, test):
self.test = test
test = Foo()
test.bar.append(
Baz(test)
推荐阅读
- c - C/LLVM:调用名称中包含非法字符的函数
- spring - Postgres 和 Spring Data JPA:运算符不存在:bytea = bigint
- python - 在另一列的值的条件下将值转换为负数
- mysql - 我如何分列到行?
- python - 根据一维 Numpy 数组的值从一个 Numpy 矩阵中获取索引?
- python - 列表中每个日期后 X 天
- apache-kafka - Kafkajs消费和生产批次问题
- blockchain - 以太坊 BC 智能合约执行重复
- c# - 如何将视图重定向到主页 - ASP.NET Core MVC
- vb.net - vb.net - 无法从另一个表单访问自定义表单属性/方法