while c = f.read(1)
John Machin
sjmachin at lexicon.net
Tue Aug 23 18:39:12 EDT 2005
Greg McIntyre wrote:
> John Machin wrote:
>
>>How about
>> for c in f.read():
>>?
>>Note that this reads the whole file into memory (changing \r\n to \n on
>>Windows) ... performance-wise for large files you've spent some memory
>>but clawed back the rather large CPU time spent doing f.read(1) once per
>>character. The "more nicely" factor improves outasight, IMHO.
>
>
> I would if only I had any kind of guarrantee on the file size but I
> don't - this code is for reading a header out of a binary file which
> uses delimiters and escape characters to mark out its fields. I didn't
> design the format, but after cleaning up the code that deals with it, I
> may *re*design it. ;)
>
>
>
>>Mild curiosity: what are you doing processing one character at a time
>>that can't be done with a built-in function, a standard module, or a
>>3rd-party module?
>
>
> Our company is designing a new file type. *sigh*.
Sigh indeed. If you need to read it a character at a time to parse it,
the design is f***ed.
> Confidentiality
> prevents me from saying any more, too. If that bugs you because it's
> not open source, sorry I need a job.
Don't be so sensitive; it has strong Biblical precedent. You can believe
in the one true god but still bow down in the house of Rimmon or Redmond.
More information about the Python-list
mailing list