3

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
DYZ
  • 55,249
  • 10
  • 64
  • 93
  • see if this can help you. https://stackoverflow.com/questions/12175964/python-method-for-reading-keypress – Avinash Dalvi Jun 01 '20 at 20:50
  • Does this answer your question? [Python method for reading keypress?](https://stackoverflow.com/questions/12175964/python-method-for-reading-keypress) – DYZ Jun 01 '20 at 20:51

1 Answers1

2

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

 print('#', sep=' ', end='', flush=True)
Steve Giles
  • 193
  • 1
  • 8