2017-07-18 74 views
1

打開一個循環內讀取多個文本文件時,開始第二次/打開我得到一個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與公開聲明第二次(在對符號環路)

希望有人能幫助我這個!

+1

某處,已分配'open'是一個字符串,但試圖調用它,彷彿它是一個函數。 – kindall

回答

2

您沿內環路的其餘部分重新分配open爲一個字符串的地方。

+0

謝謝,這是真的,開放的價格是可變的開放,將其改爲openp。令人印象深刻。我如何將此分配爲正確答案? – Willem

+0

@Willem我一般會用'_open'與領先'_'對於這種情況 – Uriel

+0

考慮只使用一個對象捆綁價格一起,那麼你可以有'price.open'&C。 – kindall

相關問題