[Python-Dev] Re: PEP 288: Generator Attributes (original) (raw)

Terry Reedy tjreedy@udel.edu
Fri, 22 Nov 2002 11:21:49 -0500


"Raymond Hettinger" <raymond.hettinger@verizon.net> wrote in message news:002b01c29203$a0b88680$125ffea9@oemcomputer...

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 logfile.write(line.upper) yield None outputCaps.data = "" # optional attribute initialization g = outputCaps(open('logfil.txt','w')) for line in open('myfile.txt'): g.data = line g.next()

-1

  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