[Tutor] Re: Convert list to literal string.

Decibels decibelshelp@charter.net
Sat Jun 28 11:08:01 2003


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])

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)

This will work also, but doesn't allow user input.

I have other functions doing stuff with command-line, but I am processing parts 
of the string. So accessing parts of it is fine.

Don't know, it might be just as fast? Was thinking it might be faster to get the quotes
from Yahoo in one swoop instead of looping.  So wanted to change to a literal string
if could figure out how. Maybe it should work, but when you send the symbols from
the command-line it doesn't unless I pass each one seperately. I must be doing something
wrong.

Dave


On Saturday 28 June 2003 09:43 am, Derrick 'dman' Hudson wrote:
> On Sat, Jun 28, 2003 at 09:40:06AM -0500, Decibels wrote:
> | Having a little problem with part of my program.
> | I had a little setup program I wrote to populate a database.
> | In the setup I used literal strings for the symbols, and figured later
> | I would have it take command-line options for them.
> |
> | Problem is now, I can't get the function to work with the list, only if
> | I enter the data as literal strings.
> |
> | Example:
> |
> | stocks = "IBM,EK"
> |
> | send that to the yahooquotes module and works fine!
>
> Ok.
>
> | When I enter them from the command-line though it doesn't
> | It comes as a list and won't work.
>
> What is the code that exhibits this?
>
> Command line arguments are always strings until the application turns
> them into other data structures.
>
> | Is there a way to make a list into a literal?
>
> Lists can be converted into strings in many ways.  The one you want to
> use depends entirely on the structure of the list you have and the
> desired format of the string you want.
>
> -D