Python Print progress bar

Source: Internet
Author: User

1 ImportSYS2 Import Time3total_size=102124Recv_size=05 defProgress (percent,width=50):6     ifPercent > 1:#if the percentage is greater than 1, take 1.7Percent=18Show_str= ('[%%-%ds]'%width)% (int (percent*width) *'#')9     #altogether 50 #,%d unsigned integers,-representing left-aligned, non-newline output, two% representing a pure%, corresponding to the back of S, followed by the number of control # numbersTen     #print (SHOW_STR) #[###############] show_str, output once each time One     Print('\r%s%s%%'% (Show_str,int (percent*100)), end="', file=sys.stdout,flush=True) A     #\ r represents the beginning of the start of the meaning, \ n for the meaning of the line, Fiel representative output to where, flush=true represents no delay, immediately refreshed. The second%s is a percentage -  whileRecv_size < total_size:#when the received size is less than the total large hour -Time.sleep (0.2)#1024x768 therecv_size+=1024#every time you receive the 1024x768 -Percent=recv_size/total_size#Calculate percent 0.10027418723070897 -Progress (PERCENT,WIDTH=30)#Call the progress bar function and pass the percentages in

1 Results: 2 [##############################] 100%

Python Print progress bar

Related Article

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.