[Tutor] Re: Convert list to literal string.
Abel Daniel
abli@freemail.hu
Sat Jun 28 11:57:01 2003
Decibels wrote:
> I can make a loop and process the info. But you can pass Yahoo
> an entire list of symbols and it will return the information.
> I can make this work:
>
> def addstock_info(addstock):
> stock = addstock
> scount = len(stock)
> print "Getting Stockinfo data from Yahoo"
> for x in range(0,scount):
> results=quotes.findQuotes(stock[x])
I think this would be better written as:
def addstock_info(addstock):
print "Getting Stockinfo data from Yahoo"
for i in addstock:
results=quotes.findQuotes(i)
# Of course, we are throwing away all but the last
# result, but thats what the original code did, too
>
> With that I can pass from the command-line for example:
>
> --addstocks IBM,EK,MO,UTX
>
> and loop thru them.
>
> I was just thinking that I could do it without looping,
> since if you bypass the 'addstock' and do this:
>
> def addstock_info(addstock):
> stock = "IBM,EK,MO,UTX' #ignoring string passed from command-line
> print "Getting Stockinfo data from Yahoo"
> results=quotes.findQuotes(stock)
>
I think this is what you need:
>>> l=['IBM','EK','MO','UTX']
>>> l
['IBM', 'EK', 'MO', 'UTX']
>>> s=','.join(l)
>>> s
'IBM,EK,MO,UTX'
>>>
and pass s to quotes.findQuotes
Abel Daniel