Python - the difference in how stdout is buffered on Windows and on Linux when written to console

preview_player
Показать описание
I look at a bug/difference between Python on Windows and Linux - I show the difference in how stdout is buffered on Windows and on Linux when written to console

import sys

Test it for yourself if you have nothing better to do:
#

import sys
import time

def teletype_print(text,delay=0.3):
for ch in text:
print(ch, end="")
print("\n")

teletype_print("Hello Mofos")
#

I then go on to talk about GitHub, and also rant about how my employer loses data and why I think they are fkn idiots.

I am in a slightly less bad mood today as I found a broken bit of Oreo biscuit under my desk, so that's about as good as it gets. Stay tuned for an update on the the Spaceship game I'm making using pygame.

Got to go, there's a man coming to buy a bike I've listed on Gumtree. See you around yeah?
Thanks for watching, and KBO.
Raspberry Pi, Linux, Python,

Check out the Minimalist online python IDE :

Рекомендации по теме
Комментарии
Автор

I understand Python buffers file data by default,
open("filename.txt", 'w')
and if the program closes unexpectedly, you lose the data!

So instead of periodic .flush(), you can safegaurd against the above by disabling the buffering,
with open("filename.bin", 'wb', buffering=0) as fileHandle:
however you must open it as a BINARY?! Then you have to write ascii-text data as fileHandle.write ( "abcd".encode("utf-8"))

My question is, how does line-buffering work? If writing whole lines at once (i.e. terminated by \r\n"), can you use buffering = 1? StackOverflow shows:
0 means unbuffered,
1 means line buffered,
anything other than 0 or 1, sets the buffer size
any other positive value means use a buffer of (approximately) that size.

bennguyen
welcome to shbcf.ru