[PYTHON] How to overwrite the output to the console

When you want to count down, use print normally

for i in range(100):
    print i

Then on the console

1 2 3 4 5 …

, It will be output vertically. It's hard to see this, so like the progress meter displayed at the time of installation, when you output the next number, the previous output disappears and the next number appears there __.

When overwriting

import sys, time
for num, i in enumerate(range(100)):
    sys.stdout.write("\r%d" % num)
    sys.stdout.flush()
    time.sleep(0.01)

\ r in sys.stdout.write looks like a kid. Without it, it will not be overwritten.

When adding

import sys, time
for i in range(100):
    sys.stdout.write("=")
    sys.stdout.flush()
    time.sleep(0.01)

This will prevent the screen from being filled with useless output.

Recommended Posts

How to overwrite the output to the console
How to get colored output to the console
I want to output to the console coolly
How to operate Linux from the console
How to print debug messages to the Django console
How to erase the characters output by Python
How to use the generator
How to use the decorator
How to increase the axis
How to start the program
[Python] How to output the list values in order
How to use the zip function
How to use the optparse module
How to read the SNLI dataset
How to get the Python version
[Python] How to import the library
How to use the ConfigParser module
How to print characters to the console before booting on ARM
How to output the output result of the Linux man command to a file
How to use the Spark ML pipeline
How to solve the bin packing problem
How to set the server time to Japanese time
How to manually update the AMP cache
[Linux] How to use the echo command
How to use the Linux grep command
How to access the Datastore from the outside
How to use the IPython debugger (ipdb)
How to assign multiple values to the Matplotlib colorbar
How to calculate the volatility of a brand
How to use the C library in Python
How to specify the launch browser for JupyterLab 3.0.0
How to use MkDocs for the first time
How to specify the NIC to scan with amazon-dash
Setting to output the log of cron execution
[Python] How to change the date format (display format)
How to make scrapy JSON output into Japanese
How to try the friends-of-friends algorithm with pyfof
How to use the graph drawing library Bokeh
How to use the Google Cloud Translation API
How to operate Linux from the outside Procedure
Output python log to both console and file
How to use the NHK program guide API
[Algorithm x Python] How to use the list
How to measure line speed from the terminal
How to get the files in the [Python] folder
How to output "Ketsumaimo" as standard output in Python
How to identify the system call number ausyscall
How to Learn Kaldi with the JUST Corpus
How to find the correlation for categorical variables
[CentOS8] How to output Python standard output to systemd log
[NNabla] How to get the output (variable) of the middle layer of a pre-built network
Attempt to launch another .exe and save the console output to a text file
Read the Python-Markdown source: How to create a parser
How to use xml.etree.ElementTree
How to enter PyCharm's autocomplete feature so that it doesn't overwrite the following words
[Python] How to remove duplicate values from the list
How to create an article from the command line
How to retrieve the nth largest value in Python
How to know the port number of the xinetd service
How to use virtualenv
Think about how to program Python on the iPad