while c = f.read(1)
mwm at mired.org
Mon Aug 22 20:28:58 CEST 2005
"Greg McIntyre" <greg at puyo.cjb.net> writes:
> My files are large, hence 1 character at a time, not f.read().
There are alternatives between the two. You could read in a chunk of
reasonable size for your platform. Say 10meg on a recent workstation,
or 100meg on a current workstation.
> This is code from another employee and I'm just in the stages of going
> through it and doing a basic clean-up before I get on to a proper
> efficiency assessment, hence I don't want to change the way it works,
> just make it as short and lucid as I can.
Well, the thing that has been hinted around but not explicitly stated
is that doing thing one character at a time in Python is a "code
smell", by which I mean it's an indication that there could be a
better way to do things, and it's probably worthwhile spending a
little time looking for it. On the other hand, if you've already
planned another pass over the code, that might be the time to look
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list