How to print with getch() in one line?

Viewed 166

I have a problem in python3 .I want to print the "#" in only one line when I push "a" button in keyboard ,but with this code when I push for example 10 times the "a" ,doesn't appear the "#" ,but when I push the "q" button ,all "#" appears. Why is this happening? Also,in print function it shows me wrong the -> end=" " Code:

import getch

while True:
    char = getch.getch()
    if(char == 'a'):
        print('#', end=" ")
    elif(char == "q"):
        break
1 Answers

For Python 3, print can take an optional flush argument where the stream is forcibly flushed.

 print('#', sep=' ', end='', flush=True)
Related