Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the advanced Python libraries that novice can't put down?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What are the Python advanced libraries that beginners can't put down? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problems. Through this article, I hope you can solve this problem.

Why do I like Python?

For beginners, this is an easy programming language; another reason: a large number of out-of-the-box third-party libraries, it is 230000 user-provided software packages that make Python really powerful and popular

In this article, I selected 15 of the most useful software packages and introduced their functions and features

1. Dash

Dash is a relatively new software package, and it is ideal for building data visualization app with pure Python, so it is especially suitable for anyone working with data. Dash is a mixture of Flask,Plotly.js and React.js.

2. Pygame

Pygame is the Python decorator of the SDL multimedia library, and SDL (Simple DirectMedia Layer) is a cross-platform development library designed to provide low-level interfaces to:

Audio frequency

Keyboard

Mouse

Game stick

Graphics hardware based on OpenGL and Direct3D

Pygame is highly portable and can run on almost all platforms and operating systems. Although it has a complete game engine, you can also use this library to play MP3 files directly from Python scripts

3. Pillow

Pillow works exclusively with images, and you can use this library to create thumbnails, convert between file formats, rotate, apply filters, display images, and so on. If you need to perform batch operations on many images, this is ideal.

To learn about it quickly, look at the following code example (load and render):

4. Colorama

Colorama allows you to use colors on the terminal, which is perfect for Python scripts. The document is short and interesting, and can be found on the Colorama PyPI page.

5. JmesPath

It is very easy to use JSON in Python because JSON maps very well in the Python dictionary. In addition, Python comes with its own excellent json library for parsing and creating JSON. For me, this is one of its best functions. If I need to use JSON, I can consider using Python.

JMESPath makes it easier for Python to process JSON, allowing you to specify explicitly how to extract elements from JSON documents. Here are some basic examples to give you some idea of what it does:

6. Requests

Requests is built on urllib3, the world's most downloaded Python library, which makes Web requests very simple, powerful and versatile.

The following code example shows how easy it is to use requests.

Requests can do all the advanced work you can think of, such as:

Authentication

Use cookie

Execute POST,PUT,DELETE, etc.

Use a custom certificate

Use session Session

Use proxy

7. Simplejson

What's wrong with the local json module in Python? No! In fact, Python's json is simplejson. This means that Python takes a version of simplejson and incorporates it into each distribution. But using simplejson has some advantages:

It applies to more Python versions.

It updates more frequently than the version that comes with Python.

It has (optional) parts written in C, so it's very fast.

Because of these facts, you will often see the following in scripts that use JSON:

I will only use the default json unless you specifically need:

Speed

Things that are not in the standard library

Simplejson is much faster than json because it implements some key parts in C. Unless you're working on millions of JSON files, you won't be interested in this speed.

8. Emoji

The Emoji library is very interesting, but not everyone likes memes, and the Emoji package is very useful when analyzing perspective media data.

The following is a simple code example:

9. Chardet

You can use the chardet module to detect the character set of files or data streams. For example, this is useful when analyzing large amounts of random text. However, when you don't know what the character set is, you can also use it when working with remotely downloaded data.

10. Python-dateutil

The python-dateutil module provides a powerful extension to the standard datetime module. My experience is that where the regular Python date-time function ends, python-dateutil appears.

You can do a lot of great things with this library. I limit these examples to those I find particularly useful: fuzzy analysis of dates in log files, such as:

For more features, see the complete documentation, such as:

Calculates the relative increment (next month, next Monday, the last week of the month, etc.) and the relative increment between two given date objects.

Using a superset of the iCalendar specification, the date is calculated according to the repetition rule.

Tzinfo implementation of tzfile files (/ etc / localtime,/ usr / share / zoneinfo, etc.), TZ environment strings (all known formats), iCalendar format files, given range (with the help of relative increments), local computer time zone, fixed offset time zone, UTC time zone, and time zone based on the Windows registry.

Based on the latest world time zone information from Olsen database.

Use the Western,Orthodox or Julian algorithm to calculate the Easter Sunday date for any year.

11. Progress bar: progress and tqdm

It's a little cheating here because it's two bags, but it's unfair to ignore one of them.

You can create your own progress bar, which may be interesting, but using progress or tqdm packages is faster and less error-prone.

Progress

With this package, you can easily create a progress bar:

Tqdm

The functionality of tqdm is roughly the same, but it seems to be up to date. Let's start with some demonstrations in the form of gif animation:

12. IPython

I'm sure you know the interactive shell of Python, which is a good way to run Python. But do you also know IPython shell? If you often use interactive shells, but you don't know IPython, you should check it out!

Some of the features provided by the enhanced IPython shell include:

Comprehensive object introspection.

Enter a history that persists across sessions.

Cache the output during a session with automatically generated references.

Tab completion, which supports completion of python variables and keywords, file names and function keywords by default.

The Magic command is used to control the environment and perform many tasks related to IPython or the operating system.

Session recording and reloading.

Integrated access to the pdb debugger and Python parser.

A little-known feature of IPython: its architecture also allows for parallel and distributed computing.

IPython is the core of Jupyter Notebook, an open source Web application that allows you to create and share documents containing real-time code, equations, visualization, and narrative text.

13. Homeassistant

I like home automation. It's a hobby for me, but I still apologize for it because it now controls most of our house. I use Home Assistant to bundle all the systems in the house together. Although it is indeed a complete application, you can also install it as a Python PyPI package.

Most of our lamps and lanterns are automated, as are the blinds.

I monitor our natural gas use, electricity use and production (solar panels).

I can track the location of most calls and start operating when I enter an area, such as turning on the garage lights when I go home.

It can also control all our entertainment systems, such as Samsung TVs and Sonos speakers.

It can automatically discover most devices on the network, so it is very easy to use.

I've been using Home Assistant every day for three years and it's still in beta, but it's the best platform I've ever tried. It can integrate and control a variety of devices and protocols, and are free and open source.

If you are interested in automating the house, please make sure you have the opportunity! If you want to know more, please visit their official website. If you can, install it on Raspberry Pi. So far, this is the simplest and safest way to get started. I installed it on a more powerful server in the Docker container.

14. Flask

Flask is my entry library for creating fast Web services or simple websites. This is a micro-framework, which means that Flask aims to keep the core simple but extensible. There are more than 700 official and community extensions.

If you know you are going to develop a large Web application, you may need to work on a more complete framework. The most popular in this category is Django.

15. BeautifulSoup

If you extract some HTML from the site, you need to parse it to get what you actually need. Beautiful Soup is a Python library for extracting data from HTML and XML files. It provides an easy way to navigate, search, and modify the parse tree. It is so powerful that it can handle all kinds of HTML even if it is damaged. Believe me, HTML is often broken, so this is a very powerful feature.

Some of its main functions are:

Bautiful Soup automatically converts incoming documents to Unicode and outgoing documents to UTF-8. You don't have to think about coding.

Beautiful Soup sits on top of popular Python parsers such as lxml and html5lib, allowing you to try different parsing strategies or increase flexibility.

BeautifulSoup parses whatever you provide and does the work of traversing the tree for you. You can tell it to "find all links" or "find the table title with bold and give me the text."

After reading the above, have you mastered the methods of the advanced Python library that beginners love to put down? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report