[Fwd: while row = c.fetchone(): # syntax error???]

Bernhard Herzog herzog at online.de
Fri Aug 11 11:53:13 EDT 2000


"Alex Martelli" <alex at magenta.com> writes:

> I've already mentioned one
> class-based alternative, but another is:
> 
>     for row in iterator(c.fetchone):
>         doit(row)
> 
> with, obviously, hidden somewhere in a myutil.py...:
> 
> class iterator:
>     def __init__(self,iter):
>         self.iter=(iter,)
>     def __getitem__(self,index):
>         nextone=self.iter[0]()
>         if not nextone:
>             raise IndexError
>         return nextone

Why do you put iter into a tuple? Because functions are converted into
methods sometimes? That shouldn't happen in this case, because iter is
an instance variable. The conversion only happens for class attributes.

-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list