基本上試圖修改本教程爲貨幣的,而不是 股票:http://pythonprogramming.net/advanced-matplotlib-graphing-charting-tutorial/錯誤:主迴路只能串聯元組(而不是「STR」),以元組
與我當前的代碼我得到:
Error: main loop can only concatenate tuple (not "str") to tuple
代碼:
import urllib2
import time
CurrencysToPull = 'audusd','eurusd','usdcad'
def pullData(Currency):
try:
fileline = Currency+'.txt'
urlToVisit = 'http://finance.yahoo.com/echarts?s=Currency=X#{"allowChartStacking":true}/'+Currency+'/chartdata;type=quote:range=1y/csv'
sourcecode = urllib2.urlopen(urlToVisit).read()
splitSource = sourcecode.split('\n')
for eachLine in splitSource:
splitLine = eachLine.split(',')
if len(splitLine)==6:
if 'valuse' not in eachLine:
saveFile = open(fileLine,'a')
lineToWrite = eachLine+'\n'
saveFile.write(lineToWrite)
print 'Pulled', Currency
print 'sleeping'
time.sleep(1)
except Exception,(e):
print('main loop'), str(e)
for eachStock in CurrencysToPull:
pullData(CurrencysToPull)
三江源@martijn皮特斯 – LibertySIlver
@馬丁PIETERS但現在我得到一個錯誤pulledata沒有定義.... – LibertySIlver
@LibertySIlver:你只要運行我的循環沒有你的代碼的其餘部分? –