Python 3.4
(party!)
Petr Viktorin
[email protected]
Brněnské Pyvo, 2014-03-27
Slide 2
Slide 2 text
Python 3.3
u'string'
Slide 3
Slide 3 text
Python 3.3
u'string'
yield from
Slide 4
Slide 4 text
Python 3.3
u'string'
yield from
venv
Slide 5
Slide 5 text
Python 3.3
u'string'
yield from
venv
__qualname__
Slide 6
Slide 6 text
Python 3.3
u'string'
yield from
venv
__qualname__
unittest.mock
Slide 7
Slide 7 text
Python 3.3
u'string'
yield from
venv
__qualname__
unittest.mock
Function signature objects
Slide 8
Slide 8 text
Python 3.4
2014-03-16
Slide 9
Slide 9 text
yield from →
asyncio
Slide 10
Slide 10 text
yield from →
asyncio
"WSGI for event loops"
Slide 11
Slide 11 text
yield from →
asyncio
"WSGI for event loops"
twisted, tornado, gevent
Slide 12
Slide 12 text
yield from →
asyncio
"WSGI for event loops"
twisted, tornado, gevent
event loop, tasks, calbacks,
futures/deferreds
networking IO
Slide 13
Slide 13 text
venv →
venv + ensurepip
Slide 14
Slide 14 text
Commonly reinvented wheels
Slide 15
Slide 15 text
Commonly reinvented wheels
belong in the standard library
Slide 16
Slide 16 text
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
Slide 17
Slide 17 text
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'
Slide 18
Slide 18 text
statistics
>>> data = [1e30, 1, 3, -1e30]
>>> sum(data) / len(data)
0.0
>>> from statistics import mean
>>> mean(data)
1.0
Slide 19
Slide 19 text
__qualname__ →
Pickle format 4
Slide 20
Slide 20 text
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)
textwrap.shorten
>>> textwrap.shorten('Hello world! You are beautiful!', 20)
'Hello world! [...]'
Slide 23
Slide 23 text
with
Slide 24
Slide 24 text
with
with what?
Slide 25
Slide 25 text
with
with what?
with contextlib.suppress:
with contextlib.redirect_stdout:
Slide 26
Slide 26 text
with
with what?
with contextlib.suppress:
with contextlib.redirect_stdout:
with unittest.TestCase.subTest():
with unittest.TestCase.assertLogs():
Slide 27
Slide 27 text
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(...):