我正在尝试使用以下内容提取制表符分隔文件的前几个元素:
words = []
name_elements = []
counter = 0
for line in f:
words = line.split()
for element in words:
counter = counter + 1
if words[element].isupper():
name_elements = words[0:counter-1]
print type(counter)
当我运行此代码时,我收到此错误:
TypeError: list indices must be integers, not str
logout
即使当我运行 type(counter) 它说它是一个整数。
有什么问题?