command line argument passing

H

Hayri ERDENER

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.
best regards
 
P

Peter Hansen

Hayri said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top