我最近发现了Python属性,我一直在使用它作为获取“只读”成员的一种方式,但现在麻烦来了......我有一些“只读”数字存储在配置类中的属性中,我想在numpy / tensorflow中重用这些数字,有点像:class MyConfig: def __init__(self, val): self._val = val @property def val(self): return self._valconf = MyConfig(10)np.ones(conf.val)错误:TypeError: expected sequence object with len >= 0 or a single integer在我的实际代码中,错误是由 a 触发的,错误消息略有不同 ()。我假设错误的原因与此小示例中的相同,只有错误帮助程序消息不同。np.reshapeTypeError: 'property' object cannot be interpreted as integer我做错了什么吗?属性不能在其他函数中用于它们嵌入的值吗?
添加回答
举报
0/150
提交
取消

