Taking command line arguments from another program

aditya shukla adityashukla1983 at gmail.com
Sun Jul 27 18:06:16 EDT 2008


Hello folks ,I have a program in which a text file is generated as an output
eg

C:\prog\ prog -x test.txt
Right now whenever i have to read the test file i have to put its name
manually in my code.
eg
f=open("c:\\prog\\test.txt","r")

How ever i want to add the name of the test file dynamically to my program
ie , if every time i give

C:\prog\ prog -x test.txt
The filename (test.txt) automatically comes in
f=open("c:\\prog\\test.txt","r")

C:\prog\ prog -x file1.txt
f=open("c:\\prog\\file1","r")


in other words i do not want to do hard code the name of the file in my code
every time i need to read it.

I was reading about the sys module and i guess sys.argv would take the input
from the command line whenever i run the python script .

Please guide me in the right direction on how to tackle the problem.

Thanks in advance

Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080727/930eea7b/attachment.html>


More information about the Python-list mailing list