2017-07-18 73 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

相关问题