Ten required PEP proposal methods in Python for 200000 Python engineers

Time:2020-10-13

 

What is Pep

PEP is an abbreviation for Python enhancement proposal. The community advises Python language through pep. The new features and some changes you see in each version are through the PEP proposal, which is discussed and voted by the community decision-making level, and finally has the functions we see. Write here, to recommend a full range of resources Python learning free answer Seven clothes nine seven seven bar five (Digital homophony) conversion can be found, here are senior programmers to share previous learning experience, learning notes, as well as work experience of first-line enterprises, and carefully collate a copy of Python zero foundation to project actual combat materials, explain the latest technology of python, prospects, learning need to leave a message of small details

0、PEP8

If you don’t know what pep8 is, you may not be a qualified Python programmer. Pep8 is a must read proposal for every Python programmer. Although Python is famous for its concise syntax, it doesn’t mean that you can write concise and elegant code. Pep8 style refers to the definition of writing python Code specification and coding principles that should be followed. We should restrict our code according to this specification in the process of writing code. Every developer should read it several times to make it clear. There are various versions of Chinese version on the Internet, which can be selected for reference.

A common convention should be maintainable, understandable, consistent, and the basis of good programming habits. It doesn’t force you to follow those rules against your will. This is Python! “- Tim Peter

Address: https://www.python.org/dev/peps/pep-0008/

1、PEP257

In addition to pep8, pep257 is a proposal to write maintainable code, which guides programmers how to write docstrings. We know that Python is a dynamic language. The advantage of dynamic language is that the code is concise, but it lacks constraints. Therefore, it is necessary to express the code through documentation to improve the maintainability of the code.

Address: https://www.python.org/dev/peps/pep-0257/
Chinese version: https://my.oschina.net/LuCastiel/blog/1552148

2、PEP20

When it comes to the hidden colored eggs in Python, pep20 is one of them, which can be imported into Python terminalthisModule, there are 20 (in fact, 19) about Python Programming Zen, not seen can be input in Python command lineimport thisTry, ironically, the source code of this module is obscure, which also shows the importance of code readability from the side of the author.
Address: https://www.python.org/dev/peps/pep-0020/

 
image

3、PEP 557

PEP 557 is a new feature added in 3.7 recently, which is called data class. This also allows programmers to write less code. Before defining a class, if the class has many properties, it will be painful to hit the keyboard during initialization, such as the previous class:

class RegularCard
    def __init__(self, rank, suit):
        self.rank = rank
        self.suit = suit

    def __repr__(self):
        return (f'{self.__class__.__name__}'
                f'(rank={self.rank!r}, suit={self.suit!r})')

    def __eq__(self, other):
        if other.__class__ is not self.__class__:
            return NotImplemented
        return (self.rank, self.suit) == (other.rank, other.suit)

You have to manually implement all those magic methods. Now you don’t want to. You just need to add a decorator to the class@dataclass

from dataclasses import [email protected] DataClassCard:    rank: str    suit: str

It is completely equivalent to the code above, which is implemented by default__init__Wait for all the magic methods.

Address: https://www.python.org/dev/peps/pep-0557/

4、 PEP 435

Enumeration is regarded as a useless thing in Python 2. It is the community who thinks that enumeration is still necessary. So PEP 435 adds an enumeration type. In other words, in modern programming, without enumeration, it can’t be called a complete language.

>>> from enum import Enum>>> class Color(Enum):...     red = 1...     green = 2...     blue = 3

Address: https://www.python.org/dev/peps/pep-0435/

5、 PEP 3156

PEP 3156 is a proposal to introduce asyncio, an asynchronous I / O framework, into Python 3.4. It provides an infrastructure for writing single thread concurrent code based on asynchronous I / O based on coroutine. Subsequently, async / away syntax and yield from syntax in PEP 380 were introduced into pep492. Since then, python has native coroutine support and no longer relies on external third-party libraries.

Address: https://www.python.org/dev/peps/pep-3156/

6、 PEP 484

Python is a dynamic language. The so-called dynamic type language means that we don’t need to specify the type when we define variables and return values. The parser will automatically judge its type when it is running. To some extent, it makes the code more concise. At the same time, the side effects brought by this language are not aspects of multi person cooperation, bug location and code readability, so I mentioned above Pep257 in this paper is to standardize code through documents, but the document is not mandatory. If you do not write it, it will have no impact on the running of the code. Therefore, PEP 484 (introduced in Python 3.5) proposes to add some features of static language – type hints at the code level. You can now declare the types of functions, methods, class parameters and return values. Similarly, there is pep526, but it is used to specify the type of variables.

def greeting(name: str) -> str:    return "Hello, {}!".format(name)

Now you can see the advantages of Java as a static language.

Address: https://www.python.org/dev/peps/pep-0484/

7、PEP 572

PEP 572 is a proposal on expression assignment. The syntax is as follows:

while chunk := file.read(8192):   process(chunk)

This proposal is more controversial in the community because it makes the father of Python quit Python’s core decision-making level angrily, because it has a big difference with other members of the community. Although the father of Python was no longer bdfl, the proposal was eventually incorporated into Python 3.8.

Address: https://www.python.org/dev/peps/pep-0572/

8、PEP 404

PEP 404, as its name suggests, is that the version number of Python 2.8 does not exist. The father of Python once said that if Python 3 wants to be compatible with Python 2, the project may have failed. Because Python 2 has too many historical burdens, python 2.7 will become the final version number of Python 2, and all new features will be added to Python 3.

Address: https://www.python.org/dev/peps/pep-0404/

9、 PEP 0

When it comes to the required PEP, it may be much more than what I listed above. Therefore, there is a special PEP that is used to index the set of all peps.

Address: https://www.python.org/dev/peps/pep-0000/

What other peps are worth reading? Write here, to recommend a full range of resources Python learning free answer Seven clothes nine seven seven bar five (Digital homophony) conversion can be found, here are senior programmers to share previous learning experience, learning notes, as well as work experience of first-line enterprises, and carefully collate a copy of Python zero foundation to project actual combat materials, explain the latest technology of python, prospects, learning need to leave a message of small details

The text and pictures of this article are from the Internet and my own ideas. They are for study and communication only. They do not have any commercial use. The copyright belongs to the original author. If you have any questions, please contact us in time for handling.

 
Like following.jpg
 
 

6 people like it

 
The way to Python

 
 
“Let’s go

Recommended Today

Construction of Vue development environment and project creation under mac

start First of all, let’s take a look at the overall development environment of Vue. Homebrew: package manager under MAC system, similar to apt get under Linux, windows control panel – install and remove program Node.jsJavaScript runtime, which is similar to simultaneous interpretation in international conferences, can’t run various programming languages directly between different systems […]