trouble with generators
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu May 10 11:30:16 EDT 2007
In <f1v4in$4qj$01$1 at news.t-online.com>, Hans-Peter Jansen wrote:
> class Gen(object):
> def records(self, cls):
> for i in range(3):
> setattr(cls, "id", "%s%s" % (cls.__doc__, i))
> yield cls
>
> […]
>
> class GenA(Gen):
> def __init__(self):
> self.genB = GenB()
>
> def records(self):
> for a in Gen.records(self, A()):
Here you create an instance of `A` and pass that *instance* and not the
*class*. If you would pass the class here, you must create objects in
`Gen.records()`.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list