Enumeration of strings and export of the constants
lnenov at mm-sol.com
Thu Nov 11 10:49:50 CET 2010
On 11/11/2010 01:30 AM, Ian wrote:
> On Nov 10, 6:12 am, lnenov<lne... at mm-sol.com> wrote:
>> Is there a better and more common way to do this?
> from itertools import count, izip
> class APINamespace(object):
> def __init__(self):
> self._named_values = 
> def enumerate(self, names, start=0, step=1):
> self._named_values.extend(izip(names, count(start, step)))
> def import_to(self, destination):
> for name, number in self._named_values:
> setattr(destination, name, number)
> Note the "step" parameter of itertools.count requires Python 2.7 or
>> And can line 6 be replaced by something less evil.
> Yes, by putting the names to be imported into their own container as
> I've done above, instead of polluting the class dictionary with them.
Thanks a lot.
It was my initial idea to pull something like that but for some
mysterious reason i failed miserably.
More information about the Python-list