I'm using Pycharm Community Edition 2022 for running this simple Python program.
This spinner program is supposed to rotate the line in place for a number of 50 times with a delay so it's smoothes out the movement.
This is the working code:
#spinner.py
import time
spinner_items = "\\|/—"
for _ in range(50):
for item in spinner_items:
print(item, end = "")
time.sleep(0.2)
print('\b', end="")`
My problem is when I try to run the program in the terminal with the command python spinner.py
it doesn't output anything.
PyCharm Run result, how it should output:
Terminal command result (why is it stuck?):
Why doesn't the terminal output the same as the Pycharm IDE? What could there be done so the terminal has the same output as the IDE?
I expected that the PyCharm IDE and the terminal output to be the same, being that it's the same program.
CodePudding user response:
Use
flush=True
import time spinner_items = "\\|/—" for _ in range(50): for item in spinner_items: print(item, end="", flush=True) time.sleep(0.2) print('\b', end="", flush=True)
Use
-u
option,python -u spinner.py