How Python implements the screen output progress bar

Source: Internet
Author: User

The general output to the screen is a set of data at once all show up. This is because the computer in order to improve efficiency, the data will be temporarily put into the cache, and so the cache is full or the end of the operation, and then processing the data once.

A situation like a progress bar requires that a character bounce out one at a time, and flush () is required to enforce this manipulation of the data in the cache.

In class, when the file was flush (), this was finally mentioned. I'll just copy it.

Import sys,timefor i in range: Sys.stdout.write ("#") # call SYS in the screen output Sys.stdout.flush () # Flush (), no this sentence will wait until the cache is full or run to the end to show it all at once. Time.sleep (0.2) # Pause 0.2 and Continue

The effect is that the "#" number on the screen is one of the jumps out.

How Python implements the screen output progress bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.