我的问题是下面这行代码:
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
,不问任何问题。
请帮忙。当这样的事情停止进步时,编程是最糟糕的。
最佳答案
您是否有可能通过将字符串分配给具有任一名称的变量而意外地隐藏了 range
或 len
?您应该避免使用任何 built-ins作为对象名称。
关于python - range() 函数产生错误 'TypeError: ' str' object is not callable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66658533/