Georg Brandl ge...@python.org added the comment:
No, this is not intentional. Look at the docs for these attributes:
parser.largs
the current list of leftover arguments, ie. arguments that have been
consumed but are neither options nor option arguments. Feel free to modify
parser.largs,
Domen Kožar ielect...@gmail.com added the comment:
I always used optparse like this, using the rargs (maybe this is not main
intention, but worked so far):
import optparse
parser = optparse.OptionParser()
parser.add_option('--test', action='store_true')
Option at 0x7f55bdb32dd0: --test
Georg Brandl ge...@python.org added the comment:
Not a bug -- you have to tell argparse that you expect a positional argument.
Try without the '--' and an argument that doesn't start with '-', and it will
still give you that error.
--
nosy: +georg.brandl
resolution: - invalid
Domen Kožar ielect...@gmail.com added the comment:
I agree — not the best example, here is a better one explaining what behavior
should not exist:
parser = argparse.ArgumentParser()
parser.add_argument('foobar', action='store')
parser.add_argument('foobar2', nargs='?')
R. David Murray rdmur...@bitdance.com added the comment:
Still looks like it is working as designed to me. Argpase is *parsing* the
arguments, that's part of the whole point. What you are observing is what I
would expect from a well behaved unix command (*arguments* before the -- are
just
Domen Kožar ielect...@gmail.com added the comment:
Optparse behaved like that, how would one get the same results with argparse?
That is by having variable positional parameters to command. And at the same
time stop at --.
--
___
Python tracker
R. David Murray rdmur...@bitdance.com added the comment:
Optparse left you to parse the arguments:
import optparse
p = optparse.OptionParser()
p.add_option('--test', action=store_true)
Option at 0x96521bc: --test
p.parse_args(['--test', 'foo', '--', 'foo2'])
(Values at 0x97020a4: {'test':
New submission from Domen ielect...@gmail.com:
Sample code:
parser = argparse.ArgumentParser()
parser.add_argument('-v', action='store_true')
parser.add_argument('foo')
parser.parse_args(['-v', '--', '--foo'])
Namespace(foo='--foo', v=True)
parser = argparse.ArgumentParser()
Changes by Benjamin Peterson benja...@python.org:
--
assignee: - bethard
nosy: +bethard
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9077
___
Changes by Eric Smith e...@trueblade.com:
--
nosy: +eric.smith
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9077
___
___
Python-bugs-list mailing
10 matches
Mail list logo