How to write fast into a file in python?

Roy Smith roy at panix.com
Sat May 18 15:37:06 EDT 2013


In article <mailman.1813.1368904489.3114.python-list at python.org>,
 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.

The delay was important.  It took more than one character time for the 
print head to get back to the left margin.  If you kept sending 
printable characters while the print head was still flying back, they 
would get printed in the middle of the line (perhaps blurred a little).

There was also a dashpot which cushioned the head assembly when it 
reached the left margin.  Depending on how well adjusted things were 
this might take another character time or two to fully settle down.

You can still see the remnants of this in modern Unix systems:

$ stty -a
speed 9600 baud; rows 40; columns 136; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 
= M-^?; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon 
-ixoff -iuclc ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 
vt0 ff0
isig icanon iexten echo echoe -echok -echonl -noflsh -xcase -tostop 
-echoprt echoctl echoke

The "nl0" and "cr0" mean it's configured to insert 0 delay after 
newlines and carriage returns.  Whether setting a non-zero delay 
actually does anything useful anymore is an open question, but the 
drivers still accept the settings.



More information about the Python-list mailing list