Re: Generator metadata/attributes

2009-01-08 Thread Ant
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' % (logMixin.describe(), stream) >         logMixin._debug('Created %s' % self) > >

Re: Generator metadata/attributes

2009-01-08 Thread Gerard Flanagan
On Thu, 08 Jan 2009 08:42:55 -0600, Rob Williscroft wrote: > > def mydecorator( f ): > def decorated(self, *args): > logging.debug( "Created %s", self.__class__.__name__ ) > for i in f(self, *args): > yield i > return decorated > can optionally be written as: def mydecorator

Re: Generator metadata/attributes

2009-01-08 Thread Rob Williscroft
wrote in news:053df793-9e8e-4855-aba1-f92482cd8922 @v31g2000vbb.googlegroups.com in comp.lang.python: > class TaggedWrapper(): > > def __init__(self, generator, logMixin, stream): > self.__generator = generator > self.__tag = '%...@%s' % (logMixin.describe(), stream) >

Re: Generator metadata/attributes

2009-01-08 Thread acooke . org
Thanks folks. Will write my own class Andrew PS So for the record, this works and isn't as ugly/verbose as I was expecting: class TaggedWrapper(): def __init__(self, generator, logMixin, stream): self.__generator = generator self.__tag = '%...@%s' % (logMixin.describe()

Re: Generator metadata/attributes

2009-01-07 Thread Rob Williscroft
wrote in news:d301c93a-8a73-4cbb-9601-fe0c18a94f97 @v5g2000prm.googlegroups.com in comp.lang.python: > I realise I could create my own wrapper that implements __next__ (I am > using Python 3 and haven't checked the exact interface required, but I > guess it's something like that), and add the inf

Re: Generator metadata/attributes

2009-01-07 Thread Jeff McNeil
You'll see the same behavior if you attempt to add an attribute to an instance of object as well. >>> object().t = 5 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 't' >>> You'll have to build your own iterator or wrap the generator obje

Re: Generator metadata/attributes

2009-01-07 Thread James Stroud
acooke@gmail.com wrote: Hi, (I searched back and found some previous discussion on generator attributes that seemed to be related to callable generators - this is NOT that, as far as I can tell) I want to associate some data with a generator. This is in a decorator function, as it happens;