[issue2444] Adding __iter__ to class Values of module optparse

Guilherme Polo report at bugs.python.org
Fri Mar 21 16:41:37 CET 2008


New submission from Guilherme Polo <ggpolo at gmail.com>:

Hi,

Doing (opts, args) = parser.parse_args(), supposing parser is an
OptionParser instance, gets you an instance of class Values into opts.

This patch adds the __iter__ method to the class Values so it is
possible to iterate over the options you could have received. This is
useful when all your options are required and you don't want to use a
lot of if's to check if they are all there (for example).

Right now it is possible to do this but you would have to iterate over
opts.__dict__, an ugly way as I see.

----------
components: Library (Lib)
files: optparse__iter__.diff
keywords: patch
messages: 64244
nosy: gpolo
severity: normal
status: open
title: Adding __iter__ to class Values of module optparse
versions: Python 2.6
Added file: http://bugs.python.org/file9801/optparse__iter__.diff

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2444>
__________________________________


More information about the Python-bugs-list mailing list