Whenever I run a method, I have included "confirmation" messages to let the user know the current process. The problem is that the two print statements print after the for loop, instead of one before and one after. See the code snippet below.
print("looping...",end="")
for x in range(100000000):
pass
print("ok")
Here, there is a notable pause and then both print statements output to the terminal. However, when I use a self-made print function, such as:
def hprint(*args,end='\n'):
for item in args:
sys.stdout.write(str(item)+' ')
sys.stdout.write(end)
sys.stdout.flush()
The first print message is sent to the terminal, there is a pause, and then the second one follows. Why is this? What is the difference between print()
and my hprint()
function that causes this?