command line argument passing
Peter Hansen
peter at engcorp.com
Fri Jul 22 09:10:38 EDT 2005
Hayri ERDENER wrote:
> hi to all,
> is it possible in python to pass arguments by using command prompt in
> windows 2000 and XP ?
> for example:
> sourceCode.py factorial 4
> gives me the factorial of 4 namely 24.
Yes, the arguments are available as a list in sys.argv .
Remember that you need to import "sys" before you can access that, and
that the values will be returned as strings, so if they should be
treated as numbers it's up to you to convert them.
Use of the getopt or optparse modules is recommended to work with
command line arguments more effectively.
-Peter
More information about the Python-list
mailing list