python - range() 函数产生错误 'TypeError: ' str' object is not callable'

标签 python typeerror

我的问题是下面这行代码:

zreal_zimg_dfs = [pd.concat([zreal_dfs[i], zimg_dfs[i]], axis = 1) for i in range(len(filestrings))]

如果 filestrings 变量与特定形式匹配,则从目录中获取。然后使用以下代码将它们排序并收集为字符串数组:

#Setting up die cast adress-string we use with glob
string = str(DATA_DIR.joinpath('Checkup_*_NMC_{nmc_nr}_*EIS000{EIS_nr}.csv'.format(nmc_nr = nmc_nr, EIS_nr = EIS_nr)))

#Grab all the strings in the folder that fit our die
filestrings = [name for name in glob.glob(string)]
filestrings.sort(key = natural_keys)

我要疯了,因为这以前有效,但现在我得到了错误

TypeError: 'str' object is not callable

我明智地打印出语句,发现罪魁祸首是这个

  print(range(len(filestrings)))
TypeError: 'str' object is not callable

同时

print(len(filestrings))

简单地输出24,不问任何问题。

请帮忙。当这样的事情停止进步时,编程是最糟糕的。

最佳答案

您是否有可能通过将字符串分配给具有任一名称的变量而意外地隐藏了 rangelen?您应该避免使用任何 built-ins作为对象名称。

关于python - range() 函数产生错误 'TypeError: ' str' object is not callable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66658533/

相关文章:

python - 删除用户输入的Python

python - python 搜索中出现'builtin_function_or_method'对象不可迭代'错误?

Python 类型错误 : unsupported operand type(s) for +: 'NoneType' and 'str'

javascript - 类方法不是函数吗?

python - 注释栏时无法更改宽度

python - 如何在具有指定错误概率的图像中添加合成噪声

python - urllib.parse vs urlparse : How do I get python 2. 7 识别urllib?

python - Seaborn factor plot hue 要求不为空 "cells"

python - 为什么在嵌套数据结构上减少 getitem 会失败?

python - 合并字典时出现类型错误 : unsupported operand type(s) for |: 'dict' and 'dict'