[Tutor] sys.argv?

Remco Gerlich scarblac@pino.selwerd.nl
Mon, 27 Nov 2000 17:14:00 +0100


On Mon, Nov 27, 2000 at 10:57:48AM -0500, Scott Ralph Comboni wrote:
> Question about using sys.argv
> 
> Example of problem:
> 
> #!/usr/bin/env python
> import sys
> 
> def test(name, n):
>        print name, n + 1
> 
> test(sys.argv[1], sys.argv[2])
> 
> ./test.py Foo 3
> 
> 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?
> Most likely something stupid on my part.

It never was an int, command line arguments are strings. So yes, use
int() or another function like that.

Remco Gerlich