[Tutor] passing in string from command line

lonetwin lonetwin@yahoo.com
Fri, 7 Dec 2001 15:54:55 +0530


Hey There
On Thursday 06 December 2001 23:16, you wrote:
> Another Basic enough question I hope you can help with!
>
> I'm reading in values from the command line that I want to assign to
> variables within the code, i.e
>
> >>python file.py number word
>
> I know how to pass the typed number into a variable, i.e,
>
> --------------------
> try:
>    variable1 =int(sys.argv[1])
> except:
>    print "Sorry, but you did not enter a number"
>    sys.exit()
> -------------------
>
> What's the equivalent to "variable1 =int(sys.argv[1])" for assigning the
> entered word to a variable, something like this??????........
> "variable2 =string(sys.argv[2])"

 No, it's something like this :
    variable2 = sys.argv[2]
          The sys.argv list is a list of *strings* that are passed as 
command-line arguments.

Peace
Steve
-- 
----------------------------------------------
Every oak tree started out as a 
couple of nuts who stood their ground.
                                    Anonymous
----------------------------------------------