I have been trying to run the following code but have looked over stack exchange and Google extensively but can not find the reason why this code keeps giving the following error.
main loop cannot concatenate 'str' and 'tuple' objects
I'm using Python version 2.7.6 on Ubuntu.
>>> print (sys.version)
2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2]
Any help would be much appreciated . Thanks in advance.
import urllib2
import time
stocksToPull ='AAPL','GOOG','MSFT','CMG','AMZN','EBAY','TSLA'
def pullData(stock):
try:
fileLine = stock+'.txt'
urlToVisit = 'http://ichart.finance.yahoo.com/table.csv?s='+stocksToPull
print urlToVisit
sourceCode = urllib2.urlopen(urlToVisit).read()
splitSource = sourceCode.split('\n')
for eachLine in splitSource:
splitLine = eachLine.split(',')
if len(splitLine)==7:
if 'value' not in eachLine:
saveFile = open(fileLine,'a')
lineToWrite = eachLine+'\n'
saveFile.write(lineToWrite)
print 'Pulled',stocksToPull
print 'sleeping'
time.sleep(1)
except Exception,e:
print 'main loop',str(e)
for eachStock in stocksToPull:
pullData('eachStock')