1

In the code below, the diamond characters (\4) are not printed immediately but after the loop is completed. Any ideas why?

from os import system
from time import sleep

def load():
    system('cls')
    i = 0
    sleep(1)
    print("\n\n\n\n\n\n\n\n\n\n\n\t\t\t Loading ", end=' ')
    for i in range(6):
        sleep(1)
        print("\4", end=' ')
        sleep(2) 
load()  
SiHa
  • 7,830
  • 13
  • 34
  • 43
Bharath Kumar R
  • 131
  • 2
  • 6

1 Answers1

1

The printing is working in Python IDLE for me. In Windows cmd it does not. Removing the end=' ' solves this, but then each diamond gets printed on a new line.

Depending on your OS you have to change the line ending. Check this page for more info on that: Python print on same line


This is working on Windows:

from os import system
from time import sleep
import sys

def load():
    system('cls')
    i = 0
    sleep(1)
    sys.stdout.write("\n\n\n\n\n\n\n\n\n\n\n\t\t\t Loading ")
    for i in range(6):
        sleep(1)
        sys.stdout.write("\4")
        sys.stdout.flush()
        sleep(2)

load()  
rinkert
  • 6,593
  • 2
  • 12
  • 31