Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39411 > unrolled thread

Re: Help me debug this script with argparse and if statements

Started byChris Angelico <rosuav@gmail.com>
First post2013-02-21 21:13 +1100
Last post2013-02-21 21:13 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help me debug this script with argparse and if statements Chris Angelico <rosuav@gmail.com> - 2013-02-21 21:13 +1100

#39411 — Re: Help me debug this script with argparse and if statements

FromChris Angelico <rosuav@gmail.com>
Date2013-02-21 21:13 +1100
SubjectRe: Help me debug this script with argparse and if statements
Message-ID<mailman.2153.1361441619.2939.python-list@python.org>
On Thu, Feb 21, 2013 at 9:05 PM, Santosh Kumar <sntshkmr60@gmail.com> wrote:
> parser.add_argument(
>     'install',
>     nargs='?',
>     help='install myapp'
>     )
>
> parser.add_argument(
>     'uninstall',
>     nargs='?',
>     help='uninstall myapp'
>     )
>
> args = parser.parse_args()

What you've done is make your program expect arguments, not options.
Try running your script --help and you'll see how it parses. Whatever
keyword is given goes into args.install, and if you provide a second
arg, it'll become args.uninstall.

To do what you're looking for there, I wouldn't bother with argparse
at all - I'd just look at sys.argv[1] for the word you're looking for.
Yes, it'd be a bit strict and simplistic, but by the look of things,
you don't need sophistication.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web