Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I clear a printed line and replace it with updated variable IDLE [duplicate]

I need to clear a printed line, but so far I have found no good answers for using python 3.7, IDLE on windows 10. I am trying to make a simple code that prints a changing variable. But I don't want tons of new lines being printed. I want to try and get it all on one line.

Is it possible to print a variable that has been updated later on in the code?

Do remember I am doing this in IDLE, not kali or something like that.

Thanks for all your help in advance.

like image 262
hemopoco Avatar asked Jan 30 '26 08:01

hemopoco


1 Answers

The Python language definition defines when bytes will be sent to a file, such as sys.stdout, the default file for print. It does not define what the connected device does with the bytes.

When running code from IDLE, sys.stdout is initially connected to IDLE's Shell window. Shell is not a terminal and does not interpret terminal control codes other than '\n'. The reasons are a) IDLE is aimed at program development, by programmers, rather than program running by users, and developers sometimes need to see all the output from a program; and b) IDLE is cross-platform, while terminal behaviors are various, depending on the system, settings, and current modes (such as insert versus overwrite).

However, I am planning to add an option to run code in an IDLE editor with sys.stdout directed to the local system terminal/console.

like image 76
Terry Jan Reedy Avatar answered Jan 31 '26 20:01

Terry Jan Reedy