This question already has answers here:
Loading animation in python
(3 answers)
Closed 7 years ago.
Is it possible to show something like this in Python?
Checking.
Checking..
Checking...
Checking.
I want it to just show one line of this while the script is running, but stop when it's done. The script I want to add it to is here: https://github.com/brandonusher/Python-Scripts/blob/master/check_port.py
Output the text with no newline character, then flush stdout. Output a \r to make the cursor go back to the beginning of the line. Repeat until done. Don't forget to overwrite existing text.
while True:
sys.stdout.write('\rfoo. ')
sys.stdout.flush()
delay(100)
sys.stdout.write('\rfoo.. ')
sys.stdout.flush()
delay(100)
sys.stdout.write('\rfoo...')
sys.stdout.flush()
delay(100)
Related
This question already has answers here:
How to print without a newline or space
(26 answers)
Closed last year.
I am trying to make a progress bar, but I don't want it to print a new line for each character that represents the bar (like: "#"). How do I update the line without printing it again?
This is not direct answer to question but just potential suggestion. for many "pretty" terminal formatting i have found rich python package to be very useful. for example has progress bar: link see example of what looks like in gif under progress bar section of readme
You can print a # without newline with:
print('#', end='', flush=True)
You need to change the end of line character to nothing.
print("#", end =''', flush=True )
This question already has answers here:
How to run a script forever? [duplicate]
(8 answers)
Closed 3 years ago.
I do not know how to do code that is executing over and over again. I would like to achieve something like this:
(< stands for input, > stands for output)
message=input()
print('Write down the text.')
>Write down the text.
<qwerty
>qwerty
>Write down the text.
<asd
>asd
You can achieve this with a
while True:
// code you want to execute repeatedly here
The while loop will continue to execute until the condition becomes false (which it never will, in this case) so if/when you want to break out of the loop you'll need to have use a break statement
Do you mean like this?
while True:
message=input("Write down the text: ")
print(message)
This question already has answers here:
Replace console output in Python
(12 answers)
Closed 4 years ago.
I am trying to build a game.
The game will have an item called a "pulsating crystal" (I am using \033[1;31;40m] to change the items colour), I want to it to be rainbow, so it keeps changing colours, without deleting everything else in the terminal. I used print(\033c) to clear the terminal but I just want to print the last line. I am sorry if the question is unclear or repetitive, or has another answer but I couldn't find another clear answer for my problem. PS I use Linux.
I just want to print the last line.
To print a line repeatedly, just override the line ending \n by giving the keyword argument end='\r' to print().
This question already has answers here:
Taking input from sys.stdin, non-blocking
(7 answers)
Closed 6 years ago.
Is there a way to check if there is anything entered in the shell without using raw_input?
For example instead of having something like question = raw_input("Enter Q to quit") I just want to read if anything is entered into the shell, "Q" and quit.
The reason I need this is because I don't want to block my program from executing with the raw_input. I need it to periodically check at any given point if "Q" is entered at all.
Something like this might work
import sys
data_input = sys.stdin.readlines()
print "Counted", len(data_input), "lines."
This question already has answers here:
Output to the same line overwriting previous output?
(11 answers)
Closed 6 years ago.
I'm not sure where to start with this, so even pointing me in the right direction would be helpful. I would like to update a line continuously in the terminal using python but can't figure out how to do this. I'm thinking something like top is doing with constantly updated information but not printing new lines.
So simplistically something like this:
for i in myList:
print i #but overwrite previous output rather than putting on new line
You can print a '\r' (which places the caret at the beginning of the current line) after any output:
for x in range(10):
print x, '\r',
print "\n"
You can also add sys.stdout.flush() after printing to make the output visible immediately.