How do I print Side using end=" with the included Time Module

Asked

Viewed 104 times

0

import time
for i in range(0,10,+1):
    print(".", end="")
    time.sleep(1)

I want to know how to print . sideways ex: ... During that time of 1 second... when I don’t use the end it works but printing down.

  • From the test I’ve done it’s working normally, printing side by side, second by second.

  • 1

    It can vary according to the characteristics of the terminal - in Idle one way, jupyter another way, cmd windows another, Unix terminal another - in Unix terminals it is necessary the flush, as I indicated in the reply.

1 answer

0

To continue printing on the same line as it happens, in addition to changing the end line character with the parameter end, you also need to pass the parameter flush=True to synchronize the file without the end of the line being present:

import time
for i in range(0,10,+1):
    print(".", end="", flush=True)
    time.sleep(1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.