Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python 3.4

Python 3.4

Used for a lightning talk at Pražské Pyvo and a full talk at Brněnské Pyvo, both March 2014

Petr Viktorin

July 23, 2014

More Decks by Petr Viktorin

Other Decks in Programming


  1. yield from → asyncio "WSGI for event loops" twisted, tornado,

    gevent event loop, tasks, calbacks, futures/deferreds networking IO
  2. enum >>> from enum import Enum >>> class Color(Enum): ...

    red = 1 ... green = 2 ... blue = 3 >>> for c in Color: ... print(c) Color.red Color.green Color.blue
  3. pathlib >>> from pathlib import Path >>> p = Path('.')

    >>> p.isdir() True >>> p / 'slides.tex' PosixPath('./slides.tex') >>> (p / 'slides.tex').open().readline() '\\documentclass[20pt]{beamer}\n'
  4. statistics >>> data = [1e30, 1, 3, -1e30] >>> sum(data)

    / len(data) 0.0 >>> from statistics import mean >>> mean(data) 1.0
  5. inspect CLI $ python -m inspect re:search def search(pattern, string,

    flags=0): """Scan through string looking for a match to the pattern, returning a match object, or None if no match was found.""" return _compile(pattern, flags).search(string)
  6. with with what? with contextlib.suppress: with contextlib.redirect_stdout: with unittest.TestCase.subTest(): with

    unittest.TestCase.assertLogs(): with aifc.open(...): with sunau.open(...): with select.epoll(...): with dbm.open(...): with wave.open(...):
  7. functools.partialmethod import functools class A: def greet(self, greeting, subject): print('{},

    {}!'.format(greeting, subject)) say_hello = functools.partialmethod(greet, 'Hello') A().say_hello('world') # --> Hello, world!
  8. functools.singledispatch from functools import singledispatch from collections.abc import Iterable @singledispatch

    def upper(arg): raise NotImplementedError() @upper.register(str) def _(arg): return arg.upper() @upper.register(Iterable) def _(arg): return [upper(a) for a in arg] print(upper('abc')) # --> ABC print(upper(['a', 'b', 'c'])) # --> ['A', 'B', 'C']
  9. docs.python.org/3.4/whatsnew asyncio ensurepip enum pathlib statistics pickle 4 inspect CLI

    re.fullmatch textwrap.shorten with signature support functools.partialmethod functools.singledispatch weakref.WeakMethod CPython improvements ... and more!