我有以下代码:
from yahoo_finance import Currency
symbolslist = ["EURUSD","EURGBP","EURJPY","EURRUB","USDCAD","USDCHF","AUSUSD"]
for i in range(len(symbolslist)):
symbol = symbolslist[i]
nomisma = Currency(symbol).get_rate()
quota = symbol + " = " + nomisma
print quota
我得到的结果是:
EURUSD = 1.0891
EURGBP = 0.7322
EURJPY = 129.7440
EURRUB = 63.0560
USDCAD = 1.2614
USDCHF = 0.9622
Traceback (most recent call last):
File "yahoopy.py", line 13, in <module>
quota = symbol + " = " + nomisma
TypeError: cannot concatenate 'str' and 'NoneType' objects
我知道这个错误已经在this链接中讨论过了。
但我希望我可以克服这个错误,而不诉诸mysql。
最佳答案
问题是打字错误。而不是你写的。修复它,错误将消失:
symbolslist = ["EURUSD","EURGBP","EURJPY","EURRUB","USDCAD","USDCHF","AUDUSD"]
不过,正如@BhargavRao建议的那样,使用
AUDUSD
来捕获此类错误仍然是一个好主意。关于python - 简单的字符串连接失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29331044/