Python 3.7's new features

Python 3.7 is data processing, optimization script compilation and garbage collection, and faster asynchronous I / O adds a number of new classes.
python is a language designed to simplify complex tasks. python latest version 3.7 has been officially leisure deer enter the beta release phase. Python3.7 final version will be released in June 2018, but after Python3.7 will not add new features.
python 3.7 and the most important new improvements are as follows:
reducing the number of template data class using the class code.
It may not be backward compatible changes involve exception handling Builder.
For the "development model" interpreter.
It has an object nanosecond time resolution.


Default environment utf-8 encoded utf-8 mode.
Trigger a new built-in functions of the debugger.
Python data types
we all know, Python is a process structured data to provide fast and convenient way to python class organization and management structure and behavior commonly associated with the instance data, but class has many initializer has a long-term disadvantage : they need a lot of boilerplate code to create.

So just like a normal Python classes generated classes, like running, you can also declare certain fields is "frozen" or immutable, and special methods to create property automatically (or manually override), such as "hash" or "repr .. "
Python generators exception handling
such as PEP 479 (https://www.python.org/dev/peps/PEP-0479/) said, over time, develop a change, making it easier to debug python generator stopiteration previously thrown an exception, the generator in the event of another problem can easily lead to stop the iterative, not because it does not have to iterate the content of which can lead to a lot of code defects are difficult to track.
In Python3.7, after the builder raise StopIteration, StopIteration exception will be converted to Runtimeerror abnormal, so it does not affect quietly stack frame application. This means that some less sensitive to how to deal with the behavior of the generator program throws a runtime error in Python3.7 in. In Python3.6 This behavior generates a warning is not recommended; in Python3.7, which generates a complete mistake.
A simple method is to rethink how to build a generator using the try / except when propagation stopiteration snippet captures it to the outside of the generator a better solution - for example, termination of the return statement generator, instead of manually initiated stopIteration. To learn more about how to fix this problem in existing code and how to prevent this problem in the new code, see PEP 469 (http: // www Python .org / DEV / PEPS / PEP-079 /.).
python development model
python new command interpreter line switches: -x allows developers to set options for many low-level interpreter. In Python3.7, the option -x dev enable the "development model", which is a run-time checking mechanism, there is usually a significant impact on performance, but during the commissioning of developers useful.
-X dev activation options include:
asynchronous modules debug mode which provides a more detailed logging and exception handling asynchronous operations that may be difficult to debug or reasoning.
Debugging hooks memory allocator. This is useful for people who write cpython extension. It allows a clearer runtime checking to see how Cpython internally allocate and free memory.
Enable faulthandler module to always dump back after a crash.
Python nanosecond time resolution function
in python 3.7 time a new function to return a time value nanosecond precision. Although the python is an interpreted language, but the python's core developers victor stinner encouraged to also report nanosecond precision time. The main reason is, when the processing shifts other programs (such as a database) of the value of the recording time, to avoid loss of precision.
The new function of time using the suffix "ns". For example, nanosecond time. process? Time () is the time process? time? Ns () Please note that not all functions have nanosecond time version, because some function does not benefit from it.
python utf-8 mode
Python has always supported UTF-8, in order to easily handle text strings and the surrounding environment, but the environment is still the language ASCII, UTF-8 instead of field testing mechanism is not always reliable.
python 3.7 added the so-called "utf-8 mode", the mode can be enabled -x command-line switch. The model assumes a UTF-8 locale environment provided in the posix, utf-8 mode is enabled by default, but is disabled by default in other locations, to avoid breaking backward compatibility. By default, attempt to enable utf-8 mode is worth it, but it should not be enabled in a production environment unless you are sure python use utf-8 were all interaction with the surrounding environment.
Built-break () function
Python comes with a built-in debugger, but it can also connect to third-party debugging tool, as long as they can debug API dialogue with Python itself, however, so far, python lack of a standardized approach to application from python to programmatically trigger the debugger.
Breakpoint added python 3.7 (), which is a built-in function, performs switching to allow the debugger when calling the function. The debugger is not necessarily appropriate python own pdb, it may be previously set as the preferred debugger any debugger. In the past, the debugger must manually set and called, which makes the code more verbose. Use breakpoint (), you can just use a command to invoke the debugger, and set a clear explanation between the debugger and invoke the debugger.
Other new Python3.7 characteristics
Python3.7 There are many other changes. Here are some other features you may encounter when using the latest version of Python:
thread local storage support of C-API
such as PEP 539 (https://www.python.org/dev/peps/PEP-0539/) said, thread-specific storage (TSS) API to replace the old one.

 

Guess you like

Origin www.cnblogs.com/blogst/p/11781480.html