How to write fast into a file in python?

Fábio Santos fabiosantosart at gmail.com
Sat May 18 17:19:54 EDT 2013


On 18 May 2013 20:19, "Dennis Lee Bieber" <wlfraed at ix.netcom.com> 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. 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.
>
>         TRS-80 Mod 1-4 used <cr> for "new line", I believe Apple used <lf>
> for "new line"... And both lost the ability to move down the page
> without also resetting the carriage to the left. In a world where both
> <cr><lf> is used, one could draw a vertical line of | by just spacing
> across the first line, printing |, then repeat <lf><bkspc>| until done.
> To do the same with conventional <lf> is "new line/return" one has to
> transmit all those spaces for each line...
>
>         At 300baud, that took time....



On Sat, May 18, 2013 at 6:00 PM, Carlos Nepomuceno
<carlosnepomuceno at outlook.com> wrote:
> Python really writes '\n\r' on Windows. Just check the files.
>
> Internal representations only keep '\n' for simplicity, but if you wanna keep track of the file length you have to take that into account. ;)


On Sat, May 18, 2013 at 3:29 PM, Chris Angelico <rosuav at gmail.com> wrote:
> Into two characters, not two lines, but yes. A file opened in text
> mode on Windows will have its lines terminated with two characters.
> (And it's old Macs that used to use \r. OS/2 follows the DOS
> convention of \r\n, but again, many apps these days are happy with
> Unix newlines there too.)
>
> ChrisA

Thanks for your corrections and explanations. I stand corrected and
have learned something.



More information about the Python-list mailing list