Roundup Robot added the comment:
New changeset bbecbcff0ce4 by Andrew Svetlov in branch '3.2':
Issue #11076: document the way to convert argparse.Namespace to a dict.
http://hg.python.org/cpython/rev/bbecbcff0ce4
New changeset ee4e31845977 by Andrew Svetlov in branch '3.3':
Merge issue #11076:
Andrew Svetlov added the comment:
Sorry, looks like it work already was done. Reverting: c008f070f88a
814403d824a5 ddcf09a348ca
--
nosy: +asvetlov
resolution: - duplicate
stage: patch review - committed/rejected
status: open - closed
___
Python
Chris Jerdonek added the comment:
Following up Andrew's last comment, for the record, it looks like this was done
as part of issue 8982.
--
nosy: +chris.jerdonek
superseder: - argparse docs cross reference Namespace as a class but the
Namespace class is not documented
Hobs added the comment:
Seems like a great idea. `foo(**dict(args))` is very useful.
I tested `foo(**dict(iter(o.__dict__.items(` on python 2.7 Mac OSX for my
foo and it worked well.
--
nosy: +Hobson.Lane
___
Python tracker
Changes by Eric Snow ericsnowcurren...@gmail.com:
--
nosy: +eric.snow
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11076
___
___
Python-bugs-list
Changes by Jean-Lou Dupont jeanlou.dup...@gmail.com:
--
nosy: +Jean-Lou.Dupont
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11076
___
___
Steven Bethard steven.beth...@gmail.com added the comment:
There's no argparse in 3.1, so it should only go into 2.7, 3.2 and 3.3. But
yes, the patch looks great to me too.
--
versions: -Python 3.1
___
Python tracker rep...@bugs.python.org
Virgil Dupras hs...@hardcoded.net added the comment:
Here's a documentation-only patch which adds a section about using vars() to
convert a namespace to a dict.
If this becomes a documentation issue, can we target Python 3.2.1 instead of
Python 3.3?
--
Added file:
Éric Araujo mer...@netwok.org added the comment:
+1 for this patch.
Documentation fixes are backported from the development branch to stable
branches, so yes, this will land in 3.1 too.
--
assignee: - docs@python
components: +Documentation -Library (Lib)
nosy: +docs@python
type:
Steven Bethard steven.beth...@gmail.com added the comment:
Yes, definitely `vars` deserves some description and an example in the
documentation. This isn't the first time this question has come up. =)
--
___
Python tracker rep...@bugs.python.org
Virgil Dupras hs...@hardcoded.net added the comment:
I didn't know about vars() (well, I knew it existed, but never was quite sure
what it did).
Given that I'm not a Python newbie, I'm guessing I'm not alone in this
situation. Maybe that instead of making the Namespace iterable, we should
Éric Araujo mer...@netwok.org added the comment:
Nice idea indeed, thanks for the patch.
For the doc section, I’d prefer to de-emplasize the specific use case of
**kwargs, in favor of mentioning dict conversion in a general way:
Converting the namespace to a dict
Steven Bethard steven.beth...@gmail.com added the comment:
What's wrong with `vars(args)`? That's the standard way of getting a dict from
an object, no?
Note that you're not always guaranteed to get a Namespace back (e.g. if you
pass the namespace= argument to parse_args), and I'd generally
Virgil Dupras hs...@hardcoded.net added the comment:
I went ahead and created a patch (with test and doc) making argparse.Namespace
iterable.
--
keywords: +patch -easy
Added file: http://bugs.python.org/file20648/issue11076.diff
___
Python tracker
New submission from Virgil Dupras hs...@hardcoded.net:
Currently, there is no (documented) way to easily extract arguments in an
argparse Namespace as a dictionary. This way, it would me easy to interface a
function taking a lot of kwargs like this:
args = parser.parse_args()
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
+1 for making the object readily convertible to a dictionary. That would also
serve to make it more introspectable without losing the simplicity of the
current design.
--
nosy: +rhettinger
16 matches
Mail list logo