andrew cooke wrote: > Jim Garrison wrote: >> I'm an experienced C/Java/Perl developer learning Python. >> >> What's the canonical Python way of implementing this pseudocode? [snip]
> > embarrassed by the other reply i have read, There's always some "trollish" behavior in any comp.lang.* group. Too many people treat languages as religions instead of tools. They all have strengths and weaknesses :-) > but not doing much binary i/o > myself, i suggest: > > with open(...) as f: > while (True): > buf = f.read(10000) > if not buf: break > ... > > but are you sure you don't want: > > with open(...) as f: > for line in f: > ... > > andrew For a one-off,,your first example would work fine. See the other reply from Tim Chase for a much more Pythonesque pattern. I don't want "for line in f:" because binary files don't necessarily have lines and I'm bulk processing files potentially 100MB and larger. Reading them one line at a time would be highly inefficient. Thanks -- http://mail.python.org/mailman/listinfo/python-list