Python Forum
loop only prints last character.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loop only prints last character.
#1
I want this to reprint and replace the time on the same line but its only printing the last character.
If I take out the end="\r" it prints the time vertically.

from datetime import datetime
import time


def get_time():
    now = datetime.now()
    current_time = now.strftime("%H:%M")
    return current_time

while True:
    for i in get_time():
        print(i, end="\r") # Only prints last character of get_time().
    time.sleep(60)
Result:
6
Reply


Messages In This Thread
loop only prints last character. - by mcmxl22 - Feb-17-2020, 02:04 AM
RE: loop only prints last character. - by menator01 - Feb-17-2020, 02:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  zfill prints extra et the end of a var tester_V 4 907 Mar-24-2023, 06:59 PM
Last Post: tester_V
  variable prints without being declared. ClockPillow 2 1,817 Jul-11-2021, 12:13 AM
Last Post: ClockPillow
  [solved] unexpected character after line continuation character paul18fr 4 3,415 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  Output prints Account.id at the end? LastStopDEVS 5 2,792 Dec-19-2020, 05:59 AM
Last Post: buran
  Try/Exept prints only ones tester_V 11 3,895 Nov-03-2020, 02:38 AM
Last Post: tester_V
  SyntaxError: unexpected character after line continuation character siteshkumar 2 3,184 Jul-13-2020, 07:05 PM
Last Post: snippsat
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 2,753 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  For loop prints strane values? colt 2 2,197 Sep-22-2019, 02:01 AM
Last Post: ichabod801
  Replace changing string including uppercase character with lowercase character silfer 11 6,206 Mar-25-2019, 12:54 PM
Last Post: silfer
  can you understand why this code prints None? arcbal 2 2,762 Mar-13-2019, 02:57 AM
Last Post: arcbal

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020