Re: How to iterate over the supplied options?
Greg Ward <[email protected]> Thu, 9 Sep 2004 07:59:49 -0400
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
On 09 September 2004, Thorsten Kampe said:
> Is there a way to iterate in a loop over all supplied options (or all
> defined) options?
>
> options, args = OptionParser.OptionParser.parse_args()
> shows a dictionary in "options" but I'm unable to iterate over it
> because it's wrapped in an "instance object".
This isn't really an Optik/optparse question -- it's a Python question.
The answer: use the builtin function vars(), eg.:
for option in vars(options):
value = getattr(options, option)
...
--
Greg Ward <[email protected]> http://www.gerg.ca/
Pointers are Arrays; Code is Data; Time is Money
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click