打开一个循环内读取多个文本文件时,开始第二次/打开我得到一个STR不可调用的错误。不幸的是,我无法自己解决这个问题。请看看我的代码:与内for循环开放,类型错误:“海峡”对象不是可调用(蟒蛇)
for symbol in sorted(list(symbollist.keys())):
textfile = symbol+"."+symbollist[symbol]['Country']+".txt"
textfile = textfile.lower()
index = symbollist[symbol]['Index']
country = symbollist[symbol]['Country']
ticker = symbol
name = symbollist[symbol]['Name']
if index not in data:
data[index] = {}
if country not in data[index]:
data[index][country] = {}
if ticker not in data[index][country]:
data[index][country][ticker] = {}
if name not in data[index][country][ticker]:
data[index][country][ticker][name] = {}
indexaddress = "d_all_txt\\data\\daily\\us\\nasdaq stocks\\1+2\\"
textad = (indexaddress+textfile)
print(textad)
with open(textad) as s:
print("test")
next(s)
for line in s:
输出:
d_all_txt\data\daily\us\nasdaq stocks\1+2\aaap.us.txt
test
d_all_txt\data\daily\us\nasdaq stocks\1+2\aaba.us.txt
Traceback (most recent call last):
File "E:\Historical stock data\import in DB.py", line 46, in <module>
with open(textad) as s:
TypeError: 'str' object is not callable
我以试图打开这两个文件分别/手动:
textad = "d_all_txt\\data\\daily\\us\\nasdaq stocks\\1+2\\aaap.us.txt"
或
textad = "d_all_txt\\data\\daily\\us\\nasdaq stocks\\1+2\\aaba.us.txt"
问题只发生时在代码arives与公开声明第二次(在对符号环路)
希望有人能帮助我这个!
某处,已分配'open'是一个字符串,但试图调用它,仿佛它是一个函数。 – kindall