<div dir="ltr">Hello folks ,I have a program in which a text file is generated as an output<br>eg<br><br>C:\prog\ prog -x test.txt <br>Right now whenever i have to read the test file i have to put its name manually in my code.<br>
eg<br>f=open("c:\\prog\\test.txt","r")<br><br>How ever i want to add the name of the test file dynamically to my program ie , if every time i give <br><br>C:\prog\ prog -x test.txt <br>The filename (test.txt) automatically comes in <br>
f=open("c:\\prog\\test.txt","r")<br><br>C:\prog\ prog -x file1.txt <br>f=open("c:\\prog\\file1","r")<br><br><br>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.<br>
<br>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 .<br><br>Please guide me in the right direction on how to tackle the problem.<br><br>
Thanks in advance<br><br>Aditya<br><br></div>