On Friday, Nov 22, 2002, at 09:46 Europe/Amsterdam, Raymond Hettinger wrote: > 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() I don't like it, there's "Magic! Magic!" written all over it. Generators have always given me that feeling (you start reading them as a function, then 20 lines down you meet a "yield" and suddenly realize you have to start reading at the top again, keeping in mind that this is a persistent stack frame), but with the __self__ plus the fact that you local variables may not be what they appear to be makes it hairy. You basically cannot understand the code without knowing the code of the caller. There's also absolutely no way to get encapsulation. So count me in for a -1. Generators have to me always felt more "class-instance-like" than "function-like", and I guess this just goes to show it. -- - Jack Jansen <Jack.Jansen@oratrix.com> http://www.cwi.nl/~jack - - If I can't dance I don't want to be part of your revolution -- Emma Goldman -
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4