[Tutor] python - files

2019-01-26 Thread Asad
Hi All , I would like to know how do I make and option file as an argument on command propmnt in python . At present I using : if len(sys.argv) == 3: first = sys.argv[1] second = sys.argv[2] else: print "enter the second argument" It works well for the following comman

Re: [Tutor] python - files

2019-01-26 Thread Alan Gauld via Tutor
On 26/01/2019 08:20, Asad wrote: >At present I using : > > if len(sys.argv) == 3: > first = sys.argv[1] > second = sys.argv[2] > else: > print "enter the second argument" > It works well for the following command : > python test.py file1 file2 Correct because it tests if the

Re: [Tutor] python - files

2019-01-26 Thread Mats Wichmann
On 1/26/19 1:20 AM, Asad wrote: > Hi All , > >I would like to know how do I make and option file as an argument on > command propmnt in python I don't know your context for asking this question. Alan has already explained what you need to do for your issue, and whatever your needs it is

Re: [Tutor] python - files

2019-01-26 Thread Cameron Simpson
Mats has mentioned the modules getopt and argparse etc. These are primarily aimed at option parsing ("-v", "-o foo"). Your situation occurs _after_ the option parsing (in your case, there are no options). Alan has talked about explicitly checking the length of sys.argv, much as you are doing,