打開一個循環內讀取多個文本文件時,開始第二次/打開我得到一個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