Home >Backend Development >Python Tutorial >Five Python libraries that make everyday coding easier

Five Python libraries that make everyday coding easier

王林
王林forward
2023-04-12 14:40:221765browse

Today we will study some very useful third-party modules that can make our daily coding easier and more convenient.

​sh

https://github.com/amoffat/sh

If you have ever used the subprocess library in Python, then we are very familiar with it. It's possible to be disappointed with it, it's not the most intuitive library, can be a bit complex, and has difficulty handling the output of low-level system calls.

But the sh library ends the pain of inefficient use of subprocesses. Using the sh library, we can make almost any system call we want, as if it were an ordinary function, which makes executing these calls cumbersome. Be more simple and intuitive. We can use them just like normal Python functions.

Here is an example of using ls​ to get the contents of a directory from sh:

Five Python libraries that make everyday coding easier

All we have to do is import the system call like a normal function, preferably The part is that all functions are dynamically generated, so we should have access to most binaries that already exist in the underlying system.

Next time when we need to make some system calls, we can try using sh.

rstr

https://github.com/leapfrogonline/rstr

If we need some easily accessible random data the number of times is uncountable Whether it's building tests for your code, filling buffers, or fuzzing your code with random data to see where it breaks, the rstr library has us covered.

This handy little library allows us to generate different types of random string data. It can generate alphanumeric data, special symbols, and even use regular expressions to build complex data patterns.

For example, suppose we want a string of numbers of a certain length. We can do this using the following rstr snippet:

Five Python libraries that make everyday coding easier

#This will print out a randomly selected 10-digit number, convenient!

IPython

https://ipython.org/

IPython is not an ordinary module, it is an incredible interactive shell Modules that enhance our Python REPL. IPython brings a great set of features to the interactive Python shell, such as autocompletion, colored output, and run details.

Five Python libraries that make everyday coding easier

Introducing classes and inspecting functions becomes much easier with IPython. The command history is easier to navigate, and we also get powerful tab completion and autocomplete functionality similar to Zsh.

Humanize

https://github.com/jmoiron/humanize

This library is really exciting, it will take date, time and Numbers, etc., and "humanize" them into human-readable phrases like "three o'clock" or "ten billion", and even better it does this automatically!

For example, let's say we're dealing with a bunch of very large numbers (think millions and billions) and want to display them in a more user-friendly way. This library can do it without even trying:

Five Python libraries that make everyday coding easier

Ouptu:

400.0 million

The human module is also great for calculating our stock market returns (or Loss...) and presented in an easy-to-read format.

Emoji

https://github.com/carpedm20/emoji/

Finally we introduce an interesting library that combines emoticons Symbols are added to the text. No one wants to copy and paste emojis directly into their code, or fumble through confusing character codes.

Here's an example of how to add a winking emoji in code:

Five Python libraries that make everyday coding easier

This will print out the actual emoji, now when the user gets an error in the console , you can wink at them.

The above is the detailed content of Five Python libraries that make everyday coding easier. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete