Re: proposal: another file iterator

2006-01-16 Thread Bengt Richter
On 15 Jan 2006 18:58:53 -0800, Paul Rubin wrote: >Jean-Paul Calderone <[EMAIL PROTECTED]> writes: >> Which is only very slightly longer than your version. I would like >> it even more if iter() had been written with the impending doom of >> lambda in mind, so that this

Re: proposal: another file iterator

2006-01-15 Thread Paul Rubin
Jean-Paul Calderone <[EMAIL PROTECTED]> writes: > Which is only very slightly longer than your version. I would like > it even more if iter() had been written with the impending doom of > lambda in mind, so that this would work: > > for chunk in iter('', f.read, blocksize): > ... > >

Re: proposal: another file iterator

2006-01-15 Thread Benji York
Jean-Paul Calderone wrote: > When I just want the dumb version, I tend to write this: > > for chunk in iter(lambda: f.read(blocksize), ''): ... > > Which is only very slightly longer than your version. I would like it > even more if iter() had been written with the impending doom of lam

Re: proposal: another file iterator

2006-01-15 Thread Raymond Hettinger
Paul Rubin wrote: > I find pretty often that I want to loop through characters in a file: > > while True: > c = f.read(1) > if not c: break > ... > > or sometimes of some other blocksize instead of 1. It would sure > be easier to say something like: > >for c in f.iterbytes():

Re: proposal: another file iterator

2006-01-15 Thread Jean-Paul Calderone
On 15 Jan 2006 16:44:24 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: >I find pretty often that I want to loop through characters in a file: > > while True: > c = f.read(1) > if not c: break > ... > >or sometimes of some other blocksize instead of 1. It would sure >be eas

proposal: another file iterator

2006-01-15 Thread Paul Rubin
I find pretty often that I want to loop through characters in a file: while True: c = f.read(1) if not c: break ... or sometimes of some other blocksize instead of 1. It would sure be easier to say something like: for c in f.iterbytes(): ... or for c in f.iterbytes(bl