Write text to file with disabling buffer in Python3

Robin Dong 2018-12-13 14:27

In Python2 era, we could use these code to write the file without buffer:

file = open('my.txt', 'w', 0)

But in Python3 we can only write binary file by disabling buffer:

file = open('my.txt', 'wb', buffering = 0)

The only way to write text file without buffering is:

file = open('my.txt', 'w')

Adding ‘flush()’ everywhere is a terrible experience for a programmer who need to migrate his code from Python2 to Python3. I really want to know: what’s in Python3’s developers mind ?

[返回] [原文链接]