August 26th, 2004, 07:08 PM
i want to make a clock thing tha is just
and that is it. Is there a way to change this on the same line without printing the variable again. Just like a normal clock on a computer.
August 26th, 2004, 11:13 PM
Here's my stab at the question, hope it helps.
The 2 in %2d ensures that you always have (at least) two character spaces. For example:
from datetime import datetime
current_time = datetime.today()
display_str = "%2d:%2d"%( current_time.hour, current_time.minute )
You probably want to modify this, however, to be %02d. This will fill the empty spaces with 0's, such that:
This will get you the desired string format of a system clock. But as for a way to change this on the same line without printing the variable again, could you please elaborate?
August 27th, 2004, 05:02 AM
You can use the \backspace character to remove the characters from the console, so then all you have to do is print the new string.
Note: I havnt tested this but you should get the general idea.
times = ('01:00', '02:00', '03:00', '04:00', '05:00', '06:00')
for time in times:
print time + '\b\b\b\b\b\b',
Hope this helps,
August 27th, 2004, 01:44 PM
its basically a normal clock like the one on youre computer screen. every minute it would change but there is still only 4 numbers total