Python“List”对象不可调用?
我试图在使用正则表达式和dict的地方运行此代码。我需要将匹配的元素放入正确的列表中,但我得到了错误。TypeError:“list”对象不可调用。谁能告诉我我做错了什么Python“List”对象不可调用?,python,Python,我试图在使用正则表达式和dict的地方运行此代码。我需要将匹配的元素放入正确的列表中,但我得到了错误。TypeError:“list”对象不可调用。谁能告诉我我做错了什么 dir='newDSSP' for tname in os.listdir(dir): file=dir+os.sep+tname ndfile=open(file) tname=dict() tname.setdefault('A',[[],[]]) tname.setdefault(
dir='newDSSP'
for tname in os.listdir(dir):
file=dir+os.sep+tname
ndfile=open(file)
tname=dict()
tname.setdefault('A',[[],[]])
tname.setdefault('B',[[],[]])
tname.setdefault('C',[[],[]])
tname.setdefault('D',[[],[]])
for ndline in ndfile:
t=re.match(r'(\s+|\S+)+\t\w+\t(\w)\t(\w)\t(\w|\s)', ndline)
k=t.group(2)
if k =='A':
tname['A'](0).append(t.group(3))<--- **#Error here**
tname['A'](1).append(t.group(4))
elif k =='B':
tname['B'](0).append(t.group(3))
tname['B'](1).append(t.group(4))
elif k =='C':
tname['C'](0).append(t.group(3))
tname['C'](1).append(t.group(4))
elif k =='D':
tname['D'](0).append(t.group(3))
tname['D'](1).append(t.group(4))
ndfile.close()
你有
tname['A'](0).append(t.group(3))
但tname['A']不是一个包含两个列表的列表吗?那样的话,你想
tname['A'][0].append(t.group(3))
x始终是一个函数调用,因此类似于tname['C']0的东西试图将tname['C']作为参数为0的函数调用。也许您打算用方括号作为列表索引?好的,这很有帮助。非常感谢!好的,我明白了,主人!谢谢你的帮助!