How to flush output of Python print function

How to flush output of Python print function

take an optional flush argument

1
print("Hello world!", flush=True)

overwrite print function with default set to flush = True

1
2
def print(*objects, sep=' ', end='\n', file=sys.stdout, flush=True):
__builtins__.print(*objects, sep=sep, end=end, file=file, flush=flush)

lambda function

1
2
message = lambda x: print(x, flush=True, end="")
message('I am flushing out now...')