[issue24419] In argparse action append_const doesn't work for positional arguments

2016-06-20 Thread paul j3
Changes by paul j3 : -- status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyt

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-22 Thread py.user
py.user added the comment: Tested on argdest.py: #!/usr/bin/env python3 import argparse parser = argparse.ArgumentParser() parser.add_argument('x', action='append') parser.add_argument('x', action='append_const', const=42, metavar='foo') parser.add_argument('x', action='append_const', const=43

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-22 Thread paul j3
paul j3 added the comment: To wrap this up, the correct way to specify that 2 or more positionals share a 'dest' is to supply that dest as the first parameter. If the help should have something else, use the `metavar`. import argparse parser = argparse.ArgumentParser() parser.add_

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-18 Thread paul j3
paul j3 added the comment: (Important correction at the end of this post) The test that you are complaining about occurs at the start of the 'add_argument' method: def add_argument(self, *args, **kwargs): """ add_argument(dest, ..., name=value, ...) add_argument(opt

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-18 Thread py.user
py.user added the comment: paul j3 wrote: > You can give the positional any custom name (the first parameter). The dest argument is not required for giving name for an optional. You can either make it automatically or set by dest, it's handy and clear. >>> import argparse >>> >>> parser = argp

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-18 Thread paul j3
paul j3 added the comment: You can give the positional any custom name (the first parameter). You just can't reuse it (by giving 2 positionals the same name). And if you don't like what the 'help' shows, you can set the 'metavar'. That way only you see the positional's name. The name of a

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-17 Thread py.user
py.user added the comment: paul j3 wrote: > The name (and hence the 'dest') must be unique. The problem is in the dest argument of add_argument(). Why user can't set a custom name for a positional? We can use this list not only for positionals but for optionals too. -- __

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-17 Thread paul j3
paul j3 added the comment: None of the `append` actions makes sense with positionals. The name (and hence the 'dest') must be unique. And positionals can't be repeated. There are other ways to put a pair of values in the Namespace. For example, after parsing args.x = [42, 43] or befor

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-17 Thread py.user
py.user added the comment: paul j3 wrote: > What are you trying to accomplish in the examples with a 'dest'? To append all that constants to one list. >From this: Namespace(bar=[43], foo=[42]) To this: Namespace(x=[43, 42]) -- ___ Python tracker <

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-17 Thread paul j3
paul j3 added the comment: What are you trying to accomplish in the examples with a 'dest'? For a positional, 'dest' is derived from the 'foo' name. There is no need to supply 'dest', in fact produces the error you get. It has nothing to with this action type (as your last example demonstra

[issue24419] In argparse action append_const doesn't work for positional arguments

2015-06-09 Thread py.user
New submission from py.user: Action append_const works for options: >>> import argparse >>> >>> parser = argparse.ArgumentParser() >>> _ = parser.add_argument('--foo', dest='x', action='append_const', const=42) >>> _ = parser.add_argument('--bar', dest='x', action='append_const', const=43) >>>