Coder Social home page Coder Social logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
Could you give me a couple test cases of what you want to work? I'm a little 
confused
by your code vs your examples. For example, 'cd -' should already work fine:

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('dir')
>>> parser.parse_args(['-'])
Namespace(dir='-')

For the case where you use +/- alone as flags, do you want to use the + and - 
with
spaces, e.g.:

>>> # hypothetical
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-', dest='add')
>>> parser.parse_args('- X'.split())
Namespace(add='X')

Or do you want to be able to squeeze the argument up against the +/- like this:

>>> # hypothetical
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-')
>>> parser.parse_args('-X'.split())
Namespace(add='X')

The former is relatively easy to support. The latter would be difficult because 
'-X'
looks like a mis-typed flag. I guess it would be possible to just disable the
mis-typed flag detection if an argument like the above is added, but I'd have to
think about it more.

Original comment by [email protected] on 7 Dec 2009 at 12:09

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
Just the former. I could see too much confusion easily arising from the use if 
there
wasn't a space in-between. Mostly I just want to be able to treat it as a 
standalone
bool flag or as the key to a subparser. I've used both forms in my scripts, but 
the
subparser form is probably more common.

Original comment by [email protected] on 7 Dec 2009 at 12:20

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
Added in r84:

>>> parser = argparse.ArgumentParser(prefix_chars='+-')
>>> parser.add_argument('+', dest='add')
>>> parser.add_argument('-', dest='sub')
>>> parser.parse_args(['+', '42', '-', '3'])
Namespace(add='42', sub='3')

Original comment by [email protected] on 28 Feb 2010 at 8:08

  • Changed state: Fixed

from argparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.