On Mon, Dec 13, 2010 at 2:13 PM, Robert Kern <robert.k...@gmail.com> wrote: >>> level = logging._levelNames[opt.logLevel] >> >> That doesn't work (_levelNames maps from integers to strings, we want >> the mapping from strings to integers and it is only the module globals >> that provides that). > > At least in Python 2.6, it maps both ways. But then again, it is an > _implementation _detail that should not be relied upon in your programs.
Ah, you're quite right - I didn't notice that when looking at the contents (the first entries happened to map levels to names) > I > would suggest that there should be two dictionaries as part of the > documented API, one mapping numbers to names and one mapping names to > numbers. Or functions/methods returning said dictionaries. Having the entire > mappings at hand is more useful than having functions that do the > translation. They would allow you to auto-generate UIs (e.g. the help text > for a --log-level argument or a radio box widget in a GUI). Having separate > mappings makes them easier to work with than the 2.6-style _levelNames > mapping. Definitely something worth considering for 3.3. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com