How to overide "for line in file:"
John Roth
newsgroups at jhrothjr.com
Sat Feb 21 20:15:11 EST 2004
<David Morgenthaler> wrote in message
news:tisf301qf76c8lh0jkq9086gpqoep1bb1u at 4ax.com...
> How does one overide the iterator implied by the construct "for line
> in file:"?
>
> For example, suppose I have a file containing row,col pairs on each
> line, and I wish to write a subclass of file that will transform these
> to x,y coordinates using an affine transform. I'd like it to look
> something like this (but this clearly doesn't work):
>
> class myFile(file):
> def __init__(self,name,affine):
> self.affine = affine
> file.__init__(name)
>
> def next(self):
> for line in file.__iter__(self):
> r,c = ",".split(line[:-1]
> yield self.affine(r,c)
>
>
> Thanks in advance!
I'm not sure what you're trying to do, but you may be
looking for the readline() method.
John Roth
> dave
More information about the Python-list
mailing list