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 __getitem__
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 2.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: bcward, bethard, eric.araujo
Priority: normal Keywords:

Created on 2010-06-12 01:04 by bcward, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg107620 - (view) Author: Bryan Ward (bcward) Date: 2010-06-12 01:04
It would be convenient to be able to access the resultant options from optparse using the syntax

options['some_option']

instead of options.some_option

Or additionally it would be nice to have a way to produce a dictionary of the options.  This would be nice to have to do something to the effect of

dictOptions = options.to_dict()

obj = SomeObject(**dictOptions)
msg107635 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-12 08:38
Thanks for your report and your ideas for Python :)
Some remarks:

1) New features have to target 3.2;  2.6 is the current stable version (only security and documentation fixes) and 2.7 is to be released really soon (end of the 2.x line);

2) Can you explain why options['thing'] would be more convenient than options.thing?

3) You can get a dict today with vars(options). (By the way, please open two reports for two requests in the futures.)

4) optparse is superseded by argparse, I don’t know if new features will be added to optparse.
msg107694 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-06-12 20:27
Given that the one obvious way of using dict-style syntax given a Python object is to call vars(), I thing adding a __getitem__ is probably a bad idea.
msg107697 - (view) Author: Bryan Ward (bcward) Date: 2010-06-12 20:40
Thanks for your help and I apologize for the unnecessary ticket.  I was unfamiliar with vars() which seems to accomplish what I wanted.
msg107698 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-12 20:43
Don’t hesitate to propose future ideas to the python-ideas mailing list
http://mail.python.org/mailman/listinfo/python-ideas
History
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53225
2010-06-12 20:43:10eric.araujosetresolution: rejected
messages: + msg107698
stage: resolved
2010-06-12 20:40:26bcwardsetstatus: open -> closed

messages: + msg107697
2010-06-12 20:27:52bethardsetmessages: + msg107694
2010-06-12 13:45:53r.david.murraysetnosy: + bethard
2010-06-12 08:38:47eric.araujosetnosy: + eric.araujo
messages: + msg107635
2010-06-12 01:04:22bcwardcreate