Show a little respect to the operation of print

Python when we playing

Often use this function to print

It is mainly used to print some output

So that we can more easily know

The operation of the program

We often this operation

 

But not quite show

Sometimes we want to be more intuitive to see the progress of our programs running

For example, when you want to crawl a file to download it to see what progress the

This time to tell you some of Sao operation of print

 

So the next step is learning the correct posture python

 

In the end the default Python print function is \ n

That you print each statement when

Finally, to wrap both ends

For example, this

 

This is the result of this Print

 

But we want is

In a row and can be printed on the line has been refreshed

Then we can put end to change the

The default is a newline into a null character we try

 

The result is this

 

Although his party, but it is a piece out together

We can not add a refresh to force a refresh

 

Because flush defaults to False only if all the contents are then prints out a one-time

True use can be done every print is displayed in time

Use sleep to look at display

 

But for some of percentage display this operation on the bad

For example, we want to show this progress percentage

 

You must also think of the result of this bird-like

 

We hope that

Digital conversion has been on the line right

This time we can use

\ r The escape character

It can be done each time back to the beginning

We give it a try

 

After this we add \ r

You can achieve as we expected it

 

Of course, if this felt engage in a bit of trouble

There are many libraries to meet your needs such as

tqdm

 

Beautiful

 

Another example

progressbar

 

The effect is such

 

Both are more than I like library use

Well, on this issue to share this

We next see peace

Guess you like

Origin www.cnblogs.com/s-seven/p/11611532.html