How to write fast into a file in python?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat May 18 18:23:31 EDT 2013
On Sat, 18 May 2013 15:14:31 -0400, Dennis Lee Bieber wrote:
> tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos
> <fabiosantosart at gmail.com> declaimed the following in
> gmane.comp.python.general:
>
>
>> You mentioned "\n" translating to two lines, but this won't happen.
>> Windows will not mess with what you write to your file.
Windows certainly may mess with what you write to your file, if it is
opened in Text mode instead of Binary mode. In text mode, Windows will:
- interpret Ctrl-Z characters as End Of File when reading;
- convert \r\n to \n when reading;
- convert \n to \r\n when writing.
http://msdn.microsoft.com/en-us/library/z5hh6ee9(v=vs.80).aspx
>> It's just that
>> traditionally windows and windows programs use \r\n instead of just \n.
>> I think it was for compatibility with os/2 or macintosh (I don't
>> remember which), which used \r for newlines.
>>
> Neither... It goes back to Teletype machines where one sent a
> carriage return to move the printhead back to the left, then sent a line
> feed to advance the paper (while the head was still moving left), and in
> some cases also provided a rub-out character (a do-nothing) to add an
> additional character time delay.
Yes, if you go back far enough, you get to teletype machines. But Windows
inherits its text-mode behaviour from DOS, which inherits it from CP/M.
> TRS-80 Mod 1-4 used <cr> for "new line", I believe Apple used <lf>
> for "new line"...
I can't comment about TRS, but classic Apple Macs (up to System 9) used
carriage return \r as the line separator.
--
Steven
More information about the Python-list
mailing list