[Tutor] sys.argv?

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 28 Nov 2000 04:19:53 -0800 (PST)

On Mon, 27 Nov 2000, Simon Brunning wrote:

> > From:	Scott Ralph Comboni [SMTP:scott@zenplex.com]
> > my problem is when I'm using sys.argv to pass in a number it converts to a
> > 
> > string..  Is there a way around this using sys.argv or do I have to use 
> > string.atoi(n) to convert it back to int?
> You aren't really passing it a number - you are passing it a string which
> happens to contain a number. So yes, basically, you are going to have to
> convert  to a number using atio or some such.

Also, you don't have to use the string module; one of the easier ways to
convert types is to use the builtin functions "int()", "float()", and

    x = int(sys.argv[1])
    print "%d squared is %d" % (x, x**2)