[Tutor] Command Line Arguements in Python

lonetwin lonetwin@yahoo.com
Wed, 17 Oct 2001 16:23:38 +0530

Mike wrote:
> > Normally, i'm used to using the "open"
> > command but I don't want to hard code it in anymore.
Hi Mike, 
   Since your 'Subject' says Commandline Arguments and you also said that you 
'don't ant to hard code it in anymore.' ....do you want to do something like:

$ python myfile.py [input file name] [output file name]

   If this is what you want, then like you said 'to get access to the 
inputfile and outputfile' ....just import the sys module (insert the line 
import sys at the start of your proggy)...and the command line arguments 
would be available to you as a list sys.argv[]

sys.argv[0] would be myfile.py
sys.argv[1] would be the [input file name]
sys.argv[2] would be the [output file name]

Hope that's what you were looking for.


Every oak tree started out as a 
couple of nuts who stood their ground.