Command line arguements

Henry Chang goldspin at gmail.com
Mon Jul 28 00:43:52 EDT 2008


try optparse  :)
http://docs.python.org/lib/module-optparse.html

On Sun, Jul 27, 2008 at 9:13 PM, aditya shukla
<adityashukla1983 at gmail.com>wrote:

> 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
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080727/85eaa9e8/attachment.html>


More information about the Python-list mailing list