[Tutor] Read arguments from command line
Joel Goldstick
joel.goldstick at gmail.com
Mon Mar 28 19:51:34 CEST 2011
On Mon, Mar 28, 2011 at 1:24 PM, Susana Iraiis Delgado Rodriguez <
susana.delgado_s at utzmg.edu.mx> wrote:
> Hello everyone!
>
> I want to run a python script which reads arguments from command line. I
> searched in web and the module sys.argv came up. But I don't understand how
> it works. I need to know how to pass arguments from command line and make
> the python script works from MS-DOS instead of run my program from the
> python console.
>
> Is there any documentation?
>
>
if you have the following command:
python myprogram.py first second third
sys.argv[0] will be "myprogram.py"
sys.argv[1] will be "first"
sys.argv[2] will be "second"
and so forth
If you need more complicated command line parsing you should look into
argparse
_______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110328/cf15798a/attachment.html>
More information about the Tutor
mailing list