[Tutor] sys.argv?

Jan Erik Moström lists at mostrom.pp.se
Tue Apr 17 13:52:43 CEST 2007

Reply to python at uni-code.com 07-04-17 07:26:

>I've been reading the python tutorial trying to get used to the style
>tryna understand it.  So I come across this: "sys.argv[0]" in the tutorial
>on python.org.  What is "sys.argv"?  How does it work? Can someone give me
>a simple example on how to use it?

It's how you read the argument from the command line

Example, a simple script

import sys

for x in sys.argv:
     print "Argument: ", x

and then how you can us it

>python ex.py
Argument:  ex.py
>python ex.py hello
Argument:  ex.py
Argument:  hello
>python ex.py hello world
Argument:  ex.py
Argument:  hello
Argument:  world

More information about the Tutor mailing list