What’s New In Python v3.5 In Windows 7 / 8 / 10 - Cloud Network

Networking | Support | Tricks | Troubleshoot | Tips

Buymecoffe

Buy Me A Coffee

Thursday, October 24, 2019

What’s New In Python v3.5 In Windows 7 / 8 / 10

 
Coroutines with async and await syntax

Greatly improves support for asynchronous programming in Python by adding awaitable objects, coroutine functions, asynchronous iteration, and asynchronous context managers.

Coroutine functions are declared using the new async def syntax

Example :-
>>> async def coro():
 ... return 'spam‘


Inside a coroutine function, the new await expression can be used to suspend coroutine execution until the result is available. Any object can be awaited, as long as it implements the awaitable protocol by defining the __await__() method.


A dedicated infix operator for matrix multiplication

Adds the @ infix operator for matrix multiplication. Currently, no builtin Python types implement the new operator, however, it can be implemented by defining __matmul__(), __rmatmul__(), and __imatmul__() for regular, reflected, and in-place matrix multiplication. The semantics of these methods is similar to that of methods defining other infix arithmetic operators.

Example :-

S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
 
Additional Unpacking Generalizations

Extends the allowed uses of the * iterable unpacking operator and ** dictionary unpacking operator. It is now possible to use an arbitrary number of unpackings in function calls:

Example :-

>>> print(*[1], *[2], 3, *[4, 5])
1 2 3 4 5


>>> def fn(a, b, c, d):
 ...     print(a, b, c, d)

% formatting support for bytes and bytearray

adds support for % interpolation operator to bytes and bytearray.

Example :-
>>>>>> b'Hello %b!' % b'World‘
 b'Hello World!‘

>>> b'x=%i y=%f' % (1, 2.5)
 b'x=1 y=2.500000'

Unicode is not allowed for %b, but it is accepted by %a (equivalent of repr(obj).encode('ascii', 'backslashreplace')):
 
Type Hints

Example :-
def greeting(name: str) -> str:
        return 'Hello ' + name

os.scandir() function – a better and faster directory iterator

Example :-
for entry in os.scandir(path):
          if not entry.name.startswith('.') and entry.is_file():
                 print(entry.name)

Retry system calls failing with EINTR

Example :-
An errno.EINTR error code is returned whenever a system call, that is waiting for I/O, is interrupted by a signal. Previously, Python would raise Interrupted Error in such case. This meant that, when writing a Python application, the developer had two choices:


1.  Ignore the Interrupted Error.
2.  Handle the Interrupted Error and attempt to restart the interrupted system call at every call site.

Change Stop Iteration handling inside generators
The interaction of generators and Stop Iteration in Python 3.4 and earlier was sometimes surprising, and could conceal obscure bugs. Previously, Stop Iteration raised accidentally inside a generator function was interpreted as the end of the iteration by the loop construct driving the generator.

A function for testing approximate equality
Make the Python Launcher aware of virtual environments
Elimination of PYO files
Multi-phase extension module initialization