python - 尝试模拟 Counter,收到 TypeError : 'str' object is not callable

标签 python python-2.5

我希望根据多个键获取重复记录。我使用的是 Python 2.5,因此无法使用 Counter。我正在更改代码以获得所需的结果,但收到 TypeError: 'str' object is not callable

start ="0,1,2,3"
mylist= [int(x) for x in start.split(',')]
key = itemgetter(*mylist)
file2 = open('temp_src.csv','rb')
f=[]
for row in file2:
   if row(key) not in f: error 
      f.append(row)

最佳答案

所以你交换了:

for row in file2:
    if key(row) not in f:
        f.append(row)

关于python - 尝试模拟 Counter,收到 TypeError : 'str' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35054897/

相关文章:

python - 为什么 os.lseek() 在类文件对象上比 seek() 慢?

Python装饰子类的所有方法,并提供重写的方法

python - 我可以在 Windows 中通过 ctrl-D 而不是 ctrl-Z 退出 Python 2.5 吗?

python - 浮点值等于-1.#IND

Python win32crypt.CryptProtectData 2.5 和 3.1 之间的区别?

python - 通过嵌套键合并嵌套字典?

python - 如何在十六进制转储上查找重复出现的模式?

python - Matplotlib Canvas 作为 numpy 数组人工制品

python - 如何在无法访问互联网的 Unix 服务器 (Solaris x86) 上安装 pandas 0.24?

python - Keras/Tensorflow 中带有 if 语句的自定义损失函数