Python python cleanup speed change
Is it possible to change the speed at which Python clears the content to the console? I know what can be added flush = True
to the print command (at least in the latest version of Python 3) to ensure that the content is printed, however there are global settings that can be changed so that the content is snapped to the screen more often or after a certain amount of time ...
(essentially, I want the content to be cleared faster, or at least at certain intervals, but not every print statement that would slow down the code).
+3
source to share
1 answer
You can do something like this toy example:
import time
print_interval = 1 # 1 second
last_print_time = time.time()
for i in range(100):
time.sleep(0.1) # An arbitrary time-consuming task
now = time.time()
if now - last_print_time >= print_interval:
print('something', flush=True)
last_print_time = now
else:
print('somethine else', flush=False)
0
source to share