On 27/01/2019 14:57, Asad wrote:
> print("first:", args.first)
> print("second:", args.second)
>
> When I execute the script it gives error :
>
> python python_json_20001_oratest_v1.py "file1"
> ('first:', 'file1')
> ('second:', None)
Note that the second file is None.
> Traceback (most recent
Asad wrote:
> Hi All ,
>
> I tried the following code :
>
> parser = argparse.ArgumentParser()
> parser.add_argument("first")
> parser.add_argument("second", nargs="?")
> args = parser.parse_args()
> print("first:", args.first)
>
> print("second:", args.second)
>
> When I execute th
arded message ------
> From: Peter Otten <__pete...@web.de>
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 27 Jan 2019 10:30:12 +0100
> Subject: Re: [Tutor] python - files
> Cameron Simpson wrote:
>
> > Mats has mentioned the modules getopt and argparse
On 27Jan2019 10:30, Peter Otten <__pete...@web.de> wrote:
Cameron Simpson wrote:
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).
Not argp
Cameron Simpson wrote:
> 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).
Not argparse. The main advantage over optparse is its handling
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,
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
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
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