In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the practical skills of Python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the practical skills of Python"?
1. Download YouTube videos using youtube-dl
You can easily download YouTube videos (as well as videos from many other websites) using the youtube-dl module in Python. First let's install the module using pip.
After installation, you can download the video directly from the terminal or command prompt using the following one-line command:
In addition, because youtube-dl has Python bindings, you can create Python scripts to do the same thing programmatically. You can use all the links to create a list and download the video using the shortcut script below.
Using this module, you can download not only videos, but also entire playlists, metadata, thumbnails, subtitles, comments, descriptions, audio, etc. The easiest way to do this is to add a bunch of parameters to the dictionary and pass them to the YoutubeDL object constructor. In the following sample code, I create a dictionary of ydl_options with a bunch of parameters and pass it to the constructor.
two。 Use Colorama to add colors to console output
Colorama is a beautiful cross-platform module that can add colors to console output. Let's install it using pip.
The following is sample code that uses Colorama:
The above code produces the following output:
Style.RESET_ALL explicitly resets the foreground, background and brightness. However, Colorama automatically performs this reset when the program exits.
3. Use pdb to debug code
Python has its own built-in debugger, pdb. The debugger is a very useful tool to help programmers check variables and program execution line by line. The advantage about pdb is that it is included in the standard Python library. Therefore, you can use this feature on any computer on which Python is installed. There are several ways to call the pdb debugger:
This is the sample code on Python 3.8.It uses the breakpoint () function to call pdb.
4. Use PyInstaller to convert Python code to an executable file
Few people know this, but you can convert Python scripts into stand-alone executables. The biggest advantage of this is that your Python scripts / applications can be run on computers that don't have Python (and any third-party packages) installed. PyInstaller can be run on almost all major platforms, including Windows,GNU / Linux,Mac OS X, FreeBSD, and AIX. Install it in pip using the following command:
Then, change to the directory where the program is located and run:
This generates an executable file and places it in a subdirectory named dist. PyInstaller provides a number of customizable options.
Pyinstaller is compatible with most third-party software packages, such as Django,NumPy,Matplotlib,SQLAlchemy,Pandas,Selenium.
5. Use tabulate to print out a beautiful 2D list
Most of the time, it will be troublesome to use Python to process the table output later. This is the time when tabulate is needed to save the scene. It can change your output from "output is like hieroglyphics to me" to "Wow, these hieroglyphs become very beautiful!" The last part may be a bit exaggerated, but most importantly, it will improve the readability of the output. First, install it using pip.
This is a simple code snippet that prints a 2D list as a table using tabulation:
The following GIF shows the output of the above code without a table. Guess which of the two outputs is easier to read.
Tabulate supports the following data types:
This is an example that applies to dictionaries.
It prints out a beautiful dictionary:
6. Using tqdm to make progress bar
The TQDM library allows you to create rapidly extensible progress bars for Python and CLI. You need to install the module using pip first:
Use a few lines of code so that you can add a smart progress bar to your Python script.
TQDM runs on all major platforms, such as Linux,Windows,Mac,FreeBSD,NetBSD,Solaris / SunOS. Not only that, it can be seamlessly integrated into any console, GUI and IPython / Jupyter.
7. Using ptpython to extend the standard Python shell
If you always want to know why my Python shell is sexier than yours, it's because I've been using custom Python shell. This custom Python shell ptpython makes many enhancements to the standard Python shell. Basically, if the standard Python shell and ptpython were twins, the latter would be the prettier (and more successful) of the two siblings. You can install ptpython through pip.
After installation, you can invoke it by typing it in the standard shell with ptpython. It has multiple functions on standard shell programs. Show:
In the GIF below, you can see that functions 1 and 3 are working.
At this point, I believe you have a deeper understanding of "what are the practical skills of Python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.