Removing printed lines in Python 3 [duplicate] - python

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().

Related

How To Update a Line Without Printing a new One in Python? [duplicate]

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 )

What is the difference between list1[0] and print(list1[0]) in python? [duplicate]

This question already has answers here:
In Python if you return a string,it will be displayed with quotes around it but If you print the string, it will not be shown with quotes. why? [duplicate]
(2 answers)
In Python what is it called when you see the output of a variable without printing it?
(3 answers)
Closed 2 years ago.
What is the difference between 'python' & python?
We get outputs in different forms for accessing the elements of a list.
Print statement returns output without single quote.
This is the behavior of the python REPL - when using python interactively, the returned value of whatever statement you run (as long as it is not None) gets printed to the console.
Since list1[0] returns the string 'python' and there's no more statement after that, the string gets printed. If you're running the same line in a script (not interactively), then it wouldn't print anything.
print() specifically prints to the console, and will do so regardless of whether python is running in interactive mode or not. It also formats the output to be printed - it doesn't print "what the element is", it prints "what you tell it to print". Which is why the single-quotes aren't there. print() doesn't need to say that it's a string.

New to Python, trying to do print statements. College textbook is super short not being helpful [duplicate]

This question already has answers here:
How can I print variable and string on same line in Python? [duplicate]
(18 answers)
Closed 2 years ago.
Ok so I'm working on a problem in my python class. I've gotten most of it figured out aside from print statements. I assigned the arguements correctly (I think) and am just trying to get the text to print correctly on the terminal side. What am I doing wrong here?
here is what I currently have
is the example that mine is supposed to look similar to
you could use f string print statements too like this:
print(f"distance in knots is: {distance_in_knots}")

Updating a line in terminal with python [duplicate]

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.

'\b' backspace escape character returns strange character [duplicate]

This question already has an answer here:
python IDLE shell appears not to handle some escapes correctly
(1 answer)
Closed 3 years ago.
I have a very strange problem:
>>> print('asdf\b\b\bjkl;',flush=True)
asdfjkl;
However, Stack Overflow is unable to display what appears between 'asdf' and 'jkl;'. Between them is a rectangular character, with 0008 appearing inside the rectangle.
What is the issue here? I know that the print function is supposed to return ajkl;. Is there any way to fix this?
The problem does not seem to occur in the command line.
Based on Chris Jester-Young's comment up there, I discovered that this is already a reported bug in IDLE. If you're indeed using IDLE, you'll just have to work around it somehow, depending on what you're doing with backspaces.

Categories

Resources