Enrico Zini: Python output buffering
Here's a little toy program that displays a message like a split-flap
display:
This only works if the script's stdout is unbuffered. Pipe the output through
If one wants to change the default buffering for a file descriptor, since
Python 3.7 there's a convenient
Otherwise, the technique is to reassign
If one needs all this to implement a progressbar, one should make sure to have
a look at the progressbar module
first.
#!/usr/bin/python3 import sys import time def display(line: str): cur = '0' * len(line) while True: print(cur, end="\r") if cur == line: break time.sleep(0.09) cur = "".join(chr(min(ord(c) + 1, ord(oc))) for c, oc in zip(cur, line)) print() message = " ".join(sys.argv[1:]) display(message.upper())
cat, and you get a long wait, and then the final string, without the
animation.
What is happening is that since the output is not going to a terminal,
optimizations kick in that buffer the output and send it in bigger chunks, to
make processing bulk I/O more efficient.
I haven't found a good introductory explanation of buffering in Python's
documentation. The details seem to be scattered in the io module
documentation and they mostly
assume that one is already familiar with concepts like unbuffered,
line-buffered or block-buffered. The libc documentation has a good quick
introduction
that one can read to get up to speed.
Controlling buffering in Python
In Python, one can force a buffer flush with the flush() method of the output
file descriptor, like sys.stdout.flush(), to make sure pending buffered
output gets sent.
Python's print() function also supports flush=True as an optional argument:
print(cur, end="\r", flush=True)
reconfigure()
method, which can reconfigure line buffering only:
sys.stdout.reconfigure(line_buffering=True)
sys.stdout to something that has the
behaviour one wants (code from this StackOverflow
thread):
import io # Python 3, open as binary, then wrap in a TextIOWrapper with write-through. sys.stdout = io.TextIOWrapper(open(sys.stdout.fileno(), 'wb', 0), write_through=True)
A new version 0.3.11 of
I ve mostly had the preference of controlling my data rather than depend on someone else. That s one reason why I still believe email to be my most reliable medium for data storage, one that is not plagued/locked by a single entity. If I had the resources, I d prefer all digital data to be broken down to its simplest form for storage, like email format, and empower the user with it i.e. their data.
Yes, there are free services that are indirectly forced upon common users, and many of us get attracted to it. Many of us do not think that the information, which is shared for the free service in return, is of much importance. Which may be fair, depending on the individual, given that they get certain services without paying any direct dime.


Rewrote my pomodoro technique timer.
I've been iterating on how I operate and focus. Too much focus exhausts me.
I'm trying out Focusmate's method of 50 minutes of focus time and 10 minutes of break.
The voting period and tally of votes for the Debian Project Leader election has just concluded, and the winner is Jonathan Carter!
455 of 1,018 Developers voted using the

The red commemorative plaque not only limits Orwell's tenure to the time he was permanently in the village, it omits all reference to his first wife, Eileen O'Shaughnessy, whom he married in the village church in 1936.
Wallington's Manor Farm, the inspiration for the farm in Animal Farm. The lower sign enjoins the public to inform the police "if you see anyone on the [church] roof acting suspiciously". Non-UK-residents may be surprised to learn about the systematic theft of lead.
In the past, I've talked about building a Z80-based computer. I made some progress towards that goal, in the sense that I took the initial (trivial steps) towards making something:
I released version 2.6 of
First up, I am alive and well. I have been receiving calls from friends for quite sometime but now that I have become deaf, it is a pain and the hearing aids aren t all that useful. But moreover, where we have been finding ourselves each and every day sinking lower and lower feels absurd as to what to write and not write about India. Thankfully, I ran across this 