[Python-Dev] Re: PEP 288: Generator Attributes
Fri, 22 Nov 2002 11:21:49 -0500
"Raymond Hettinger" <firstname.lastname@example.org> wrote in message
> PEP 288 has been updated and undeferred.
> Comments are solicited.
> The old proposal for generator parameter passing with g.next(val)
> has been replaced with simply using attributes in about the same
> way as classes:
> def outputCaps(logfile):
> while True:
> line = __self__.data
> yield None
> outputCaps.data = "" # optional attribute initialization
> g = outputCaps(open('logfil.txt','w'))
> for line in open('myfile.txt'):
> g.data = line
1. Having assignment of a dummy attribute to a (generator) function
unlock assignment of an attribute of the same name to the otherwise
read-only generator produced by that function is way too magical. It
also breaks the illusion of simplicity and ignorance of detail allowed
when generators are used in for loops.
2. Magical use of implicit '__self__' will likely increase questions
about the self-object as the initial parameter of methods and requests
that it be removed or worse, be made optional.
Terry J. Reedy