Skip to main content
 首页 » 编程设计

python之类型错误 : str object is not callable

2025年05月04日19pengyingh

这是我的代码:

fi=tarfile.open(os.path.join(pathin,file_in),'r') 
list-fi.getmembers() 
entries_list[] 
for lis in list: 
    name_list=lis.name() 
    entries_list.append(name_list) 
print entries_list. 

在 name_list=lis.name() 行,我收到错误 str object is not callable。你能解释一下为什么吗?

提前致谢。

请您参考如下方法:

lis.name 是一个字符串,所以 lis.name() 尝试调用这个字符串。因为字符串不可调用,所以您会收到错误消息 str object is not callable。