On 11/11/2010 01:30 AM, Ian wrote:
On Nov 10, 6:12 am, lnenov<lne...@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
3.1.

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.

Thanks again.

~Lyudmil

Cheers,
Ian
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to