Hello, everyone, today I would like to introduce to you two small tools that are easy to use in Python.
Although the usage is simple, it can greatly improve the development efficiency.
1. tqdm
When the for
loop in the program takes a lot of time to execute, we often add an 计数器
output program execution progress.
The disadvantage of this method is that it needs to write some code that is not related to the business, and it prints too much information.
If we use tqdm
a progress bar to display the execution progress of the program, the above shortcomings can be effectively avoided.
Very simple to use
import time
from tqdm import tqdm
for i in tqdm(range(100)):
time.sleep(1)
This gadget also has other useful functions, you can explore it yourself if you are interested.
2. glob
The second gadget is a module that comes with the Python library -- glob
.
It can Unix
access local files in style.
For example, we want to list all gif
files in the current directory
import glob
glob.glob('./*.ipynb')
The output is as follows:
['./cnn.ipynb', './blob.ipynb', './test.ipynb']
and many more examples
>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']
>>> glob.glob('**/*.txt', recursive=True)
['2.txt', 'sub/3.txt']
>>> glob.glob('./**/', recursive=True)
['./', './sub/']
How, is the gadget simple and efficient, haha, I hope it will be useful to everyone.
recommended article
-
Li Hongyi's "Machine Learning" Mandarin Course (2022) is here
-
Someone made a Chinese version of Mr. Wu Enda's machine learning and deep learning
-
I'm addicted, and recently I gave the company a big visual screen (with source code)
-
So elegant, 4 Python automatic data analysis artifacts are really fragrant
-
It's very fragrant, and 20 visual large-screen templates have been organized
Technology Exchange
Welcome to reprint, collect, like and support!
At present, a technical exchange group has been opened, and the group has more than 2,000 members . The best way to remark when adding is: source + interest direction, which is convenient to find like-minded friends
- Method 1. Send the following picture to WeChat, long press to identify, and reply in the background: add group;
- Method ②, add micro-signal: dkl88191 , note: from CSDN
- Method ③, WeChat search public account: Python learning and data mining , background reply: add group