Generator metadata/attributes

Ant antroy at gmail.com
Thu Jan 8 15:14:32 CET 2009


You could look at something like the following to turn the class
iteslf into a decorator (changed lines *-ed):

> class TaggedWrapper():
>
*     def __init__(self, logMixin, stream):
>         self.__tag = '%s@%s' % (logMixin.describe(), stream)
>         logMixin._debug('Created %s' % self)
>
>     def __next__(self):
>         return next(self.__generator)
>
>     def __str__(self):
>         return self.__tag

      def __call__(self, generator):
         self.__generator = generator
         return self

and then decorate your generator:

@TaggedWrapper(mixin, stream)
def myGen;
   for a in range(1,100):
        yield a

(Disclaimer: Completely untested...)




More information about the Python-list mailing list