希望这个问题还没有在这里得到解答。
当我尝试打印时:
import gparser
gp = gparser.I_Parser()
print(gp._z_matrix())
它正在发射:
Traceback (most recent call last):
File ".\__init__.py", line 4, in <module>
print(gp._z_matrix())
TypeError: 'list' object is not callable
在 gparser.py 中,属性 _z_matrix 定义如下:
@property
def _z_matrix(self):
coords = []
p = re.compile('^ [a-zA-Z] +-?[0-9]')
for line in self._file:
m = p.match(line)
if m:
coords.append(line)
return coords
我真的不明白我是怎么导致这个错误弹出的,有人能给我解释一下吗?
请您参考如下方法:
不需要调用属性来执行它们。只需访问它们(使用点 .)即可触发附加的功能。
简而言之,您通过 gp._z_matrix 调用属性 _z_matrix,然后在它执行并返回一个列表(coords) 按照定义,您正在使用 () 调用列表对象。
除了解释之外,解决方案是简单地删除 () 以避免 TypeError。
