This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: optparse.parse_args() ret value seems to be a dict but isn't
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: gward Nosy List: georg.brandl, gward, nnorwitz, rhunger
Priority: normal Keywords:

Created on 2006-07-07 09:35 by rhunger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
optparse_dict_2006-07-07.patch rhunger, 2006-07-07 09:35 patch to add dict support for class Values
Messages (4)
msg54842 - (view) Author: rhunger (rhunger) Date: 2006-07-07 09:35
...
from optparse import OptionParser
parser = OptionParser()
...
(options, args) = parser.parse_args()
print options
...

options seems to be a dict but isn't. So it's not possible to use e.g.

print "Option 1: %(firstOption)s" % options

Here it's easy to use "options.firstOption" but with a larger number of program options it would be nice to be able to use "options" as a dict directly.

(patch attached)
msg54843 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-07-25 04:06
Logged In: YES 
user_id=33168

Greg, are you using the Python tracker or only optik tracker?
msg54844 - (view) Author: Greg Ward (gward) (Python committer) Date: 2006-07-26 02:38
Logged In: YES 
user_id=14422

Don't believe __str__(): believe the docs.  In particular,
section 6.21.3.7 of the Python Library Reference is pretty
clear that options is not a dict.  See 
 
http://www.python.org/doc/2.4.3/lib/optparse-parsing-arguments.html

If you want a dict, no need to modify optparse: just use
vars(options).
msg54845 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-09-30 11:46
Logged In: YES 
user_id=849994

In any case, this is a feature request.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43632
2006-07-07 09:35:21rhungercreate