PyCon PL, Szczyrk, 2014



>>> first, second, *rest, last = \
... "a b c d e f".split()
>>> first, second, last
('a', 'b', 'f')>>> def foo(a, *args, b, **kw):
... print(a, args, b, kw)
>>> foo(1, 2, 3, b=4, c=5)
1 (2, 3) b {'c': 5}>>> raise KeyError("wut?") from ZeroDivisionError()
ZeroDivisionError
The above exception was the direct cause of
the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'wut?' BlockingIOError ChildProcessError
ConnectionError BrokenPipeError
ConnectionAbortedError ConnectionRefusedError
ConnectionResetError FileExistsError
FileNotFoundError InterruptedError
IsADirectoryError NotADirectoryError
PermissionError ProcessLookupError
TimeoutError__main__:1: ResourceWarning: unclosed file
>>> def my_generator(): ... yield from range(1,5) ... yield from range(10,15) ... >>> list(my_generator()) [1, 2, 3, 4, 10, 11, 12, 13, 14]
super(ClassName, self).method(foo, bar)
super().method(foo, bar)
>>> from __future__ import division >>> from __future__ import print_function >>> print("Three halves is written", 3/2, "with decimals.") Three halves is written 1.5 with decimals.

class TheComponent(object):
implements(ITheInterface)@implementor(ITheInterface)
class TheComponent(object):
passical = str(icalendarobject)
ical = icalendarobject.to_ical()



$ caniusepython3 --project diazo You need 3 projects to transition to Python 3. Of those 3 projects, 2 has no direct dependencies blocking its transition: repoze.xmliter (which is blocking diazo) experimental.cssselect (which is blocking diazo)
$ 2to3 -w .
$ tox __________________ summary __________________ py26: commands succeeded py27: commands succeeded ERROR: py34: commands failed pep8: commands succeeded
$ virtualenv-2.7 .venv/py27 $ virtualenv-3.4 .venv/py34
And a small script:
#!/bin/bash .venv/py27/bin/python setup.py test .venv/py34/bin/python setup.py test

if sys.version_info > (3,):
unicode = str
doctype_re_b = re.compile(
b"^<!DOCTYPE\\s[^>]+>\\s*", re.MULTILINE)
doctype_re_u = re.compile(
u"^<!DOCTYPE\\s[^>]+>\\s*", re.MULTILINE)
if isinstance(result, unicode):
result, subs = doctype_re_u.subn(
self.doctype, result, 1)
else:
result, subs = doctype_re_b.subn(
self.doctype.encode(), result, 1)$ pip install future
futurize -w -f <thespecificfixer> .

Props to

| Space | Forward |
|---|---|
| Left, Down, Page Down | Next slide |
| Right, Up, Page Up | Previous slide |
| P | Open presenter console |
| H | Toggle this help |