SlideShare una empresa de Scribd logo
1 de 70
Descargar para leer sin conexión
The  COOLEST  is  yet  
TO  COME	

{

“event”:      “PDI  DEVCON  2013”	
“author”:  “Pablo  Enfedaque”	
“twi5er”:  “pablitoev56”
> 

Today  we  are  going  to  see  a  quick  tour  through  
Python’s  newest  features	
> 

The  new  super  function	

> 

The  yield  from  statement	

> 

The  new  exception  chaining	

> 

Single-­‐‑dispatch  generic  functions	

> 

Python  virtual  environments	

> 

The  enum  module	

> 

The  asyncio  module	

> 

And  lots  of  other  new  features	

Welcome!	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  super  function	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
class SilentDict(dict):	
def __getitem__(self, key):	
"""Called to implement evaluation of self[key]	
:returns: None by default	
"""	
try:	
return super(SilentDict, self).__getitem__(key)	
except KeyError:	
return None	
	
>>> d = SilentDict()	
>>> print (d[“a”])	
None	
	
>>> d = SilentDict({"a": 1, "b": 2})	
>>> print(d["a"])	
1	
>>> print(d["a"])	
None	

Let’s  implement  a  SilentDict	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
class SilentDict(dict):	
def __getitem__(self, key):	
"""Called to implement evaluation of self[key]	
:returns: None by default	
"""	
try:	
return super().__getitem__(key)	
except KeyError:	
return None	
	
>>> d = SilentDict()	
>>> print (d[“a”])	
None	
	
>>> d = SilentDict({"a": 1, "b": 2})	
>>> print(d["a"])	
1	
>>> print(d["a"])	
None	

Let’s  implement  a  SilentDict	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

h5p://docs.python.org/3/library/
functions.html#super	
> 

PEP  3135:  New  Super	
> 

> 

h5p://www.python.org/dev/peps/pep-­‐‑3135/	

Introduced  in  Python  3.0	

> 

Standard  Library  updated  to  use  it	

> 

No  official  backport	

The  super  function	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  yield  from  statement	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Let’s  implement  itertools.chain	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
def chain(*iterables):	
# chain('ABC', 'DEF') --> A B C D E F	
for it in iterables:	
yield from it	
	
>>> list(chain('ABC', 'DEF'))	
['A', 'B', 'C', 'D', 'E', 'F']	
	
>>> list(chain([1, 2, 3], (4, 5, 6), [7, 8, 9]))	
[1, 2, 3, 4, 5, 6, 7, 8, 9]	

Let’s  implement  itertools.chain	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

PEP  380:  Syntax  for  Delegating  to  a  Subgenerator	
> 

h5p://www.python.org/dev/peps/pep-­‐‑0380/	

> 

Introduced  in  Python  3.3	

> 

No  backport	

The  yield  from  statement	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
from urllib.request import urlopen	
from urllib.error import URLError	
	
class CustomException(Exception):	
"""Out custom exception for this example""”	
	
def requester(url):	
"""Open and read given url"""	
try:	
return urlopen(url).readall()	
except URLError:	
raise CustomException	
	
def call_the_requester(url):	
return requester(url)	
	
def main_app(url):	
print(call_the_requester(url))	
	
if __name__ == "__main__":	
main_app("http://unknown_host:8765")	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
$ python3.4 raise_from_none_examples.py	
Traceback (most recent call last):	
...	
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/urllib/
request.py", line 1255, in do_open	
raise URLError(err)	
urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided,
or not known>	
	
During handling of the above exception, another exception occurred:	
	
Traceback (most recent call last):	
File "raise_from_none_examples.py", line 39, in <module>	
main_app("http://unknown_host:8765")	
File "raise_from_none_examples.py", line 35, in main_app	
print(call_the_requester(url))	
File "raise_from_none_examples.py", line 31, in call_the_requester	
return requester(url)	
File "raise_from_none_examples.py", line 27, in requester	
raise CustomException	
__main__.CustomException	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
$ python3.4 raise_from_none_examples.py	
Traceback (most recent call last):	
...	
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/urllib/
request.py", line 1255, in do_open	
raise URLError(err)	
urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided,
or not known>	
	
During handling of the above exception, another exception occurred:	
	
Traceback (most recent call last):	
File "raise_from_none_examples.py", line 39, in <module>	
main_app("http://unknown_host:8765")	
File "raise_from_none_examples.py", line 35, in main_app	
print(call_the_requester(url))	
File "raise_from_none_examples.py", line 31, in call_the_requester	
return requester(url)	
File "raise_from_none_examples.py", line 27, in requester	
raise CustomException	
__main__.CustomException	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
from urllib.request import urlopen	
from urllib.error import URLError	
	
class CustomException(Exception):	
"""Out custom exception for this example""”	
	
def requester(url):	
"""Open and read given url"""	
try:	
return urlopen(url).readall()	
except URLError as exc:	
raise CustomException from exc	
	
def call_the_requester(url):	
return requester(url)	
	
def main_app(url):	
print(call_the_requester(url))	
	
if __name__ == "__main__":	
main_app("http://unknown_host:8765")	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
$ python3.4 raise_from_none_examples.py	
Traceback (most recent call last):	
...	
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/
request.py", line 1242, in do_open	
raise URLError(err)	
urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided,
or not known>	
	
The above exception was the direct cause of the following exception:	
	
Traceback (most recent call last):	
File "raise_from_none_examples.py", line 40, in <module>	
main_app("http://unknown_host:8765")	
File "raise_from_none_examples.py", line 36, in main_app	
print(call_the_requester(url))	
File "raise_from_none_examples.py", line 32, in call_the_requester	
return requester(url)	
File "raise_from_none_examples.py", line 28, in requester	
raise CustomException from exc	
__main__.CustomException	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
from urllib.request import urlopen	
from urllib.error import URLError	
	
class CustomException(Exception):	
"""Out custom exception for this example""”	
	
def requester(url):	
"""Open and read given url"""	
try:	
return urlopen(url).readall()	
except URLError:	
raise CustomException from None	
	
def call_the_requester(url):	
return requester(url)	
	
def main_app(url):	
print(call_the_requester(url))	
	
if __name__ == "__main__":	
main_app("http://unknown_host:8765")	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
$ python3.4 raise_from_none_examples.py	
Traceback (most recent call last):	
File "raise_from_none_examples.py", line
main_app("http://unknown_host:8765")	
File "raise_from_none_examples.py", line
print(call_the_requester(url))	
File "raise_from_none_examples.py", line
call_the_requester	
return requester(url)	
File "raise_from_none_examples.py", line
raise CustomException from None	
__main__.CustomException	

40, in <module>	
36, in main_app	
32, in

28, in requester	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

Several  PEPs  involved:	
> 

PEP  3134:  Exception  Chaining  and  Embedded  
Tracebacks	
> 

> 

PEP  409:  Suppressing  exception  context	
> 

> 

h5p://www.python.org/dev/peps/pep-­‐‑3134	
h5p://www.python.org/dev/peps/pep-­‐‑0409/	

PEP  415:  Implement  context  suppression  with  
exception  a5ributes	
> 

h5p://www.python.org/dev/peps/pep-­‐‑0415	

> 

Introduced  in  Python  3.0  and  3.3	

> 

No  official  backport	

The  new  exception  chaining	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Single-­‐‑dispatch  generic  functions	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
class Duck:	
def quack(self):	
print("quack")	
	
class Cat:	
def meow(self):	
print("meow")	
	
class Dog:	
def bark(self):	
print("bark”)	
	
class Cow:	
def moo(self):	
print("moo")	
	
donald = Duck()	
garfield = Cat()	
milu = Dog()	
milka = Cow()	

Let’s  create  some  animals	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
def make_sound(animal):	
if isinstance(animal, Duck):	
animal.quack()	
elif isinstance(animal, Cat):	
animal.meow()	
elif isinstance(animal, Dog):	
animal.bark()	
else:	
raise NotImplementedError("Unknown animal")	
	
>>> make_sound(donald)	
quack	
>>> make_sound(garfield)	
meow	
>>> make_sound(milu)	
bark	
>>> make_sound(milka)	
Traceback (most recent call last):	
File "<stdin>", line 1, in <module>	
File "<stdin>", line 11, in make_sound	
NotImplementedError: Unknown animal	

Let’s  play  animals’  sounds	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
import functools	
	
	
@functools.singledispatch	
def make_sound(animal):	
raise NotImplementedError("Unknown animal")	
	
	
@make_sound.register(Duck)	
def make_duck_sound(animal):	
animal.quack()	
	
	
@make_sound.register(Cat)	
def make_cat_sound(animal):	
animal.meow()	
	
	
@make_sound.register(Dog)	
def _(animal):	
animal.bark()	

Single-­‐‑dispatch  generic  functions	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
>>> make_sound(donald)	
quack	
	
>>> make_sound(garfield)	
meow	
	
>>> make_sound(milu)	
bark	
	
>>> make_sound(milka)	
Traceback (most recent call last):	
File "<stdin>", line 1, in <module>	
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/
python3.4/functools.py", line 632, in wrapper	
return dispatch(args[0].__class__)(*args, **kw)	
File "<stdin>", line 5, in make_sound	
NotImplementedError: Unknown animal	

Single-­‐‑dispatch  generic  functions	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

h5p://docs.python.org/dev/library/
functools.html#functools.singledispatch	
> 

PEP  443:  Single-­‐‑dispatch  generic  functions	
> 

> 
> 

h5p://www.python.org/dev/peps/pep-­‐‑0443/	

Introduced  in  Python  3.4	

No  official  backport	

Single-­‐‑dispatch  generic  functions	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Python  virtual  environments	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
$ pyvenv /tmp/test_venv	
	
$ ls /tmp/test_venv/	
bin
include
lib
pyvenv.cfg	
	
$ ls /tmp/test_venv/bin/	
activate
activate.csh activate.fish python
python3
python3.4	
	
$ cat /tmp/test_venv/pyvenv.cfg	
home = /Library/Frameworks/Python.framework/Versions/3.4/bin	
include-system-site-packages = false	
version = 3.4.0	
	
$ pyvenv /tmp/test_venv --symlinks --clear --system-site-packages	
	
$ cat /tmp/test_venv/pyvenv.cfg	
home = /Library/Frameworks/Python.framework/Versions/3.4/bin	
include-system-site-packages = true	
version = 3.4.0	
	
$ ls -lAhtr /tmp/test_venv/bin/python3.4	
lrwxr-xr-x 1 pev wheel
63B 5 nov 00:21 /tmp/test_venv/bin/python3.4 -> /
Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4	

Python  virtual  environments	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
$ source /tmp/test_venv/bin/activate	
	
(test_venv) ...$ which python	
/tmp/test_venv/bin/python	
	
(test_venv) ...$ which python3.4	
/tmp/test_venv/bin/python3.4	
	
(test_venv) ...$ python	
Python 3.4.0a4 (v3.4.0a4:e245b0d7209b, Oct 20 2013, 02:43:50)	
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin	
Type "help", "copyright", "credits" or "license" for more information.	
>>> import sys	
>>> sys.prefix, sys.base_prefix	
('/private/tmp/test_venv', '/Library/Frameworks/Python.framework/Versions/3.4')	
>>> sys.exec_prefix, sys.base_exec_prefix	
('/private/tmp/test_venv', '/Library/Frameworks/Python.framework/Versions/3.4')	
	
(test_venv) ...$ deactivate	
	
$ which python	
/usr/bin/python	

Python  virtual  environments	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

Features	
> 

Supports  symbolic  links  (recommended)	

> 

Access  both  environment  and  system  site-­‐‑packages  	

> 

pyvenv.cfg  environment  configuration  file:	
> 
> 

> 

> 

home:  path  to  original  Python  installation  bin	
include-­‐‑system-­‐‑site-­‐‑packages:  access  system  site-­‐‑packages  
after  the  environment  site-­‐‑packages	
version:  Python  version  in  use	

Public  API  to  let  3rd  party  virtual  environments  customise  
the  environment  creation	
> 

Subclass  EnvBuilder  and  redefine  desired  methods	

Python  virtual  environments	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

h5p://docs.python.org/3/library/venv.html	
> 

PEP  405:  Python  Virtual  Environments	
> 

> 
> 

h5p://www.python.org/dev/peps/pep-­‐‑0405/	

Introduced  in  Python  3.3	
No  official  backport,  although  quite  similar  to  
virtualenv	

Python  virtual  environments	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  enum  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
RED, ORANGE, GREEN = range(3) # Colors	
STOPPED, RUNNING = range(2)
# Statuses	
	
	
class TrafficLight:	
def __init__(self, light_color, status):	
assert light_color in (RED, ORANGE, GREEN), "Not a valid color"	
assert status in (RUNNING, STOPPED), "Not a valid status"	
self.color = light_color	
self.status = status	
	
def print_state(self):	
color_name = "red" if self.color == RED else "green" if self.color ==
GREEN else "orange"	
status_name = "running" if self.status == RUNNING else "stopped"	
print("Traffic light is {} in color {}".format(status_name,
color_name))	
	
	
>>> my_semaphore = TrafficLight(RUNNING, RED)	
>>> my_semaphore.print_state()	
Traffic light is stopped in color orange	

Let’s  implement  a  traffic  light	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
RED, ORANGE, GREEN = range(3) # Colors	
STOPPED, RUNNING = range(2)
# Statuses	
	
	
class TrafficLight:	
def __init__(self, light_color, status):	
assert light_color in (RED, ORANGE, GREEN), "Not a valid color"	
assert status in (RUNNING, STOPPED), "Not a valid status"	
self.color = light_color	
self.status = status	
	
def print_state(self):	
color_name = "red" if self.color == RED else "green" if self.color ==
GREEN else "orange"	
status_name = "running" if self.status == RUNNING else "stopped"	
print("Traffic light is {} in color {}".format(status_name,
color_name))	
	
	
>>> my_semaphore = TrafficLight(RUNNING, RED)	
>>> my_semaphore.print_state()	
Traffic light is stopped in color orange	

Let’s  implement  a  traffic  light	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
RED, ORANGE, GREEN = range(3) # Colors	
STOPPED, RUNNING = range(2)
# Statuses	
	
	
class TrafficLight:	
def __init__(self, light_color, status):	
assert light_color in (RED, ORANGE, GREEN), "Not a valid color"	
assert status in (RUNNING, STOPPED), "Not a valid status"	
self.color = light_color	
self.status = status	
	
def print_state(self):	
color_name = "red" if self.color == RED else "green" if self.color ==
GREEN else "orange"	
status_name = "running" if self.status == RUNNING else "stopped"	
print("Traffic light is {} in color {}".format(status_name,
color_name))	
	
	
>>> my_semaphore = TrafficLight(RUNNING, RED)	
>>> my_semaphore.print_state()	
Traffic light is stopped in color orange	

Let’s  implement  a  traffic  light	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
RED, ORANGE, GREEN = range(3) # Colors	
STOPPED, RUNNING = range(2)
# Statuses	
	
	
class TrafficLight:	
def __init__(self, light_color, status):	
assert light_color in (RED, ORANGE, GREEN), "Not a valid color"	
assert status in (RUNNING, STOPPED), "Not a valid status"	
self.color = light_color	
self.status = status	
	
def print_state(self):	
color_name = "red" if self.color == RED else "green" if self.color ==
GREEN else "orange"	
status_name = "running" if self.status == RUNNING else "stopped"	
print("Traffic light is {} in color {}".format(status_name,
color_name))	
	
	
>>> STOPPED is RED and RUNNING is ORANGE	
True	
>>> (RUNNING + ORANGE) * GREEN	
4	

Let’s  implement  a  traffic  light	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
from enum import Enum	
	
	
Color = Enum("Color", "red orange green")
# Colors	
Status = Enum("Status", "stopped running") # Statuses	
	
	
class TrafficLight:	
def __init__(self, light_color, status):	
assert light_color in Color, "Not a valid color"	
assert status in Status, "Not a valid status"	
self.color = light_color	
self.status = status	
	
def print_state(self):	
color_name = "red" if self.color == Color.red else "green" if
self.color == Color.green else "orange"	
status_name = "running" if self.status == Status.running else "stopped"	
print("Traffic light is {} in color {}".format(status_name,
color_name))	
	
	
my_semaphore = TrafficLight(Status.running, Color.red)	

Introducing  the  enum  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
>>> my_semaphore = TrafficLight(Status.running, Color.red)	
Traceback (most recent call last):	
File "<stdin>", line 1, in <module>	
File "<stdin>", line 3, in __init__	
AssertionError: Not a valid color	
	
	
>>> my_semaphore = TrafficLight(Color.red, Status.running)	
>>> my_semaphore.print_state()	
Traffic light is running in color red	
	
	
>>> Status.stopped is Color.red	
False	
>>> Status.running is Color.orange	
False	
	
	
>>> (Status.running + Color.orange) * Color.green	
Traceback (most recent call last):	
File "<stdin>", line 1, in <module>	
TypeError: unsupported operand type(s) for +: 'Status' and 'Color'	

Introducing  the  enum  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
class Color(Enum): # enumaration	
red = 0	
orange = 10 # enumeration members	
green = 20
# custom non-consecutive values	
ruby = 0
# aliases	
	
>>> print(Color.green)	
Color.green	
>>> print(repr(Color.green))	
<Color.green: 20>	
	
>>> print(repr(Color.ruby))
# this is an alias	
<Color.red: 0>	
	
>>> print(Color.orange.name)
# we can retrieve a member name	
orange	
>>> print(Color["orange"])
# we can get the enum member from its name	
Color.orange	
	
>>> print(Color.orange.value) # we can retrieve a member value	
10	
>>> print(Color(10))
# we can get the enum member from its value	
Color.orange	

More  about  enum  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
class Color(Enum):	
red = 0	
orange = 10	
green = 20	
	
class Status(Enum):	
running = 0	
stopped = 1	
	
class TrafficLight:	
def __init__(self, light_color, status):	
assert light_color in Color, "Not a valid color"	
assert status in Status, "Not a valid status"	
self.color = light_color	
self.status = status	
	
def print_state(self):	
print("Traffic light is {} in color {}".format(self.status.name,
self.color.name))	
	
>>> my_semaphore = TrafficLight(Color.red, Status.running)	
>>> my_semaphore.print_state()	
Traffic light is running in color red	

More  about  enum  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

And  still  more  features	
> 

Iteration  over  enumeration  members	
> 

> 

Ordered  dictionary  __members__  special  a5ribute	

Define  methods  and  class  methods	
> 

Even  redefine  __str__  or  __repr__	

> 

IntEnum  to  preserve  old  int  behaviour	

> 

@enum.unique  to  enforce  no  aliases  are  defined	

> 

Possibility  to  define  other  custom  Enum  sublcasses	

> 

Functional  API	

More  about  enum  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

h5p://docs.python.org/3.4/library/enum.html	
> 

PEP  435:  Adding  an  Enum  type  to  the  Python  
standard  library	
> 

> 

> 

h5p://www.python.org/dev/peps/pep-­‐‑0435/	

Introduced  in  Python  3.4	

Standard  Library  updated  to  use  enums	
> 
> 

> 

IntEnum  when  backwards-­‐‑compatibility  broken	
Enum  in  new  developments  and  internal  modules	

Official  backport  available  in  PyPi	
> 

h5ps://pypi.python.org/pypi/enum34/  	

The  enum  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  asyncio  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

Python’s  asynchronous  IO  Support  Rebooted	

> 

No  new  language  features,  no  new  lib  extensions	

> 

Based  on  a  customisable  event  loop	
> 

Interface  to  manage  the  event  loop  and  its  policies	

> 

Interface  to  implement  or  adapt  event  loops	
> 

Different  3rd  party  async  frameworks  could  interoperate	

> 

Coroutines,  futures  and  tasks	

> 

Transports  and  protocols	

> 

Use  yield  from  to  delegate  or  callbacks	

The  asyncio  module  (aka.  Tulip)	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

h5p://docs.python.org/3.4/library/enum.html	
> 

PEP  3156:  Asynchronous  IO  Support  Rebooted:  
the  "ʺasyncio"ʺ  Module	
> 

h5p://www.python.org/dev/peps/pep-­‐‑3156/	

> 
> 

> 

Reference  implementation  in  Python  3.4	
Expected  final  status  in  Python  3.5	

Backport  to  3.3  available  in  PyPi	
> 

h5ps://pypi.python.org/pypi/asyncio/0.1.1	

The  asyncio  module	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

unicode,  unicode  everywhere	

> 

generators,  generators  everywhere	
> 

or  iterators	

> 

uniNest.mock  (port  of  Michael  Foord’s  mock)	

> 

contextlib.ExitStack  and  contextlib.ContextDecorator	

> 

Be5er  GIL  (but  still  Global  Interpreter  Lock)	

> 

concurrent.futures  for  async  computation	

> 

Qualified  name  for  classes  and  functions	

> 

selectors  module	

> 

…	

And  still  lots  of  new  features	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Q&A	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Are  we  done  yet?	

Q&A	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Are  we  done  yet?	
> 

Not  yet	
> 

Only  22  slides  missing	
> 

16  only  with  pictures,  and  even  1  animated  GIF	
> 

Sorry,  no  ki5ens	

Q&A	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Should  we  move  now  to  
Python  3?	

Q&A	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Should  we  move  now  to  
Python  3?	
> 

YES	
> 

Well,  maybe  NO	
> 

Well,  let  me  explain	

Q&A	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
h5p://www.python.org/download/releases/2.7/	
	
Release  schedule:	
>  …	
>  2.7.0  final:  July  3,  2010	
>  …	
>  2.7.6  candidate  1:  October  26,  2013	
>  ???	
>  2.7.X  end  of  support:  ≈  2016	
	
	

Python  2.7	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
h5p://www.python.org/download/releases/3.4.0/	
	
Release  schedule:	
>  3.4.0  alpha  4:  October  20,  2013	
>  3.4.0  beta  1  (feature  freeze):  November  24,  2013	
>  3.4.0  beta  2:  January  5,  2014	
>  3.4.0  candidate  1:  January  19,  2014	
>  3.4.0  candidate  2:  February  2,  2014	
>  3.4.0  final:  February  23,  2014	
	
	

Python  3.4	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
The  long  journey  to  Python  3	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Meanwhile,  most  of  the  community	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
> 

Great  features  are  waiting  us  in  Python  3	

> 

We  are  beyond  half  the  planned  life  of  Python  2.7	
> 

> 

Most  3rd  party  dependencies  already  in  Python  3	
> 

> 

Python  2.6  is  officially  retired  with  2.6.9  release	
Or  we  could  return  to  OSS  all  that  we  have  been  given	

Porting  to  Python  3  is  not  such  a  big  deal	
> 

In  most  of  the  cases	

> 

So,  no  more  excuses	

> 

It’s  time  to  start  moving  to  Python  3	

Conclusions	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Conclusions	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
Thanks  for  coming!	
	
	

Slides:  h5p://goo.gl/Yrzt0Q  	
Code:  h5p://goo.gl/V9bv72  	

Q&A	
{  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}

Más contenido relacionado

La actualidad más candente

Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIsJames Pearce
 
Metrics-Driven Engineering at Etsy
Metrics-Driven Engineering at EtsyMetrics-Driven Engineering at Etsy
Metrics-Driven Engineering at EtsyMike Brittain
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_netNico Ludwig
 
Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensionsOleksandr Zhevzhyk
 
Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesJose Manuel Jurado Diaz
 
SolrJ: Power and Pitfalls - Jason Gerlowski, Lucidworks
SolrJ: Power and Pitfalls - Jason Gerlowski, LucidworksSolrJ: Power and Pitfalls - Jason Gerlowski, Lucidworks
SolrJ: Power and Pitfalls - Jason Gerlowski, LucidworksLucidworks
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Railstielefeld
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to CeleryIdan Gazit
 
Metrics-Driven Engineering
Metrics-Driven EngineeringMetrics-Driven Engineering
Metrics-Driven EngineeringMike Brittain
 
Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...Alexander Granin
 
Automate that
Automate thatAutomate that
Automate thatAtlassian
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissAndres Almiray
 
Mastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveMastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveVMware Tanzu
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDMichele Capra
 

La actualidad más candente (20)

Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIs
 
Automation puzzlers
Automation puzzlersAutomation puzzlers
Automation puzzlers
 
Metrics-Driven Engineering at Etsy
Metrics-Driven Engineering at EtsyMetrics-Driven Engineering at Etsy
Metrics-Driven Engineering at Etsy
 
Your code are my tests
Your code are my testsYour code are my tests
Your code are my tests
 
Invoke-DOSfuscation
Invoke-DOSfuscationInvoke-DOSfuscation
Invoke-DOSfuscation
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensions
 
Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best Practices
 
SolrJ: Power and Pitfalls - Jason Gerlowski, Lucidworks
SolrJ: Power and Pitfalls - Jason Gerlowski, LucidworksSolrJ: Power and Pitfalls - Jason Gerlowski, Lucidworks
SolrJ: Power and Pitfalls - Jason Gerlowski, Lucidworks
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Rails
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to Celery
 
Metrics-Driven Engineering
Metrics-Driven EngineeringMetrics-Driven Engineering
Metrics-Driven Engineering
 
Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...
 
Zendcon 09
Zendcon 09Zendcon 09
Zendcon 09
 
#ajn3.lt.marblejenka
#ajn3.lt.marblejenka#ajn3.lt.marblejenka
#ajn3.lt.marblejenka
 
Automate that
Automate thatAutomate that
Automate that
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Mastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveMastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura Bhave
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDD
 

Destacado

Execution model and other must-know's
Execution model and other must-know'sExecution model and other must-know's
Execution model and other must-know'sPablo Enfedaque
 
The (unknown) collections module
The (unknown) collections moduleThe (unknown) collections module
The (unknown) collections modulePablo Enfedaque
 
EuroPython 2015 - Decorators demystified
EuroPython 2015 - Decorators demystifiedEuroPython 2015 - Decorators demystified
EuroPython 2015 - Decorators demystifiedPablo Enfedaque
 
Sprayer: low latency, reliable multichannel messaging
Sprayer: low latency, reliable multichannel messagingSprayer: low latency, reliable multichannel messaging
Sprayer: low latency, reliable multichannel messagingPablo Enfedaque
 
Propuestas didácticas para las clases de conversación de español 2014
 Propuestas didácticas para las clases de conversación de español 2014 Propuestas didácticas para las clases de conversación de español 2014
Propuestas didácticas para las clases de conversación de español 2014Espanolparainmigrantes
 

Destacado (7)

Why I miss MongoDB
Why I miss MongoDBWhy I miss MongoDB
Why I miss MongoDB
 
Execution model and other must-know's
Execution model and other must-know'sExecution model and other must-know's
Execution model and other must-know's
 
The (unknown) collections module
The (unknown) collections moduleThe (unknown) collections module
The (unknown) collections module
 
EuroPython 2015 - Decorators demystified
EuroPython 2015 - Decorators demystifiedEuroPython 2015 - Decorators demystified
EuroPython 2015 - Decorators demystified
 
Python 2 vs. Python 3
Python 2 vs. Python 3Python 2 vs. Python 3
Python 2 vs. Python 3
 
Sprayer: low latency, reliable multichannel messaging
Sprayer: low latency, reliable multichannel messagingSprayer: low latency, reliable multichannel messaging
Sprayer: low latency, reliable multichannel messaging
 
Propuestas didácticas para las clases de conversación de español 2014
 Propuestas didácticas para las clases de conversación de español 2014 Propuestas didácticas para las clases de conversación de español 2014
Propuestas didácticas para las clases de conversación de español 2014
 

Similar a Python: the coolest is yet to come

Flask patterns
Flask patternsFlask patterns
Flask patternsit-people
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftChris Bailey
 
Behind the curtain - How Django handles a request
Behind the curtain - How Django handles a requestBehind the curtain - How Django handles a request
Behind the curtain - How Django handles a requestDaniel Hepper
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTim Cull
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My PatienceAdam Lowry
 
The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88Mahmoud Samir Fayed
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и DjangoMoscowDjango
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Python Ireland
 
Projeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfProjeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfAdrianoSantos888423
 
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...DynamicInfraDays
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196Mahmoud Samir Fayed
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in pythonAndrés J. Díaz
 
The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189Mahmoud Samir Fayed
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Zagreb workshop
Zagreb workshopZagreb workshop
Zagreb workshopLynn Root
 

Similar a Python: the coolest is yet to come (20)

Decorators demystified
Decorators demystifiedDecorators demystified
Decorators demystified
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
 
Django (Web Konferencia 2009)
Django (Web Konferencia 2009)Django (Web Konferencia 2009)
Django (Web Konferencia 2009)
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) Swift
 
Behind the curtain - How Django handles a request
Behind the curtain - How Django handles a requestBehind the curtain - How Django handles a request
Behind the curtain - How Django handles a request
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applications
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)
 
Projeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdfProjeto-web-services-Spring-Boot-JPA.pdf
Projeto-web-services-Spring-Boot-JPA.pdf
 
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
 
The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Django Celery
Django Celery Django Celery
Django Celery
 
Zagreb workshop
Zagreb workshopZagreb workshop
Zagreb workshop
 

Último

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Python: the coolest is yet to come

  • 1. The  COOLEST  is  yet   TO  COME { “event”:      “PDI  DEVCON  2013” “author”:  “Pablo  Enfedaque” “twi5er”:  “pablitoev56”
  • 2. >  Today  we  are  going  to  see  a  quick  tour  through   Python’s  newest  features >  The  new  super  function >  The  yield  from  statement >  The  new  exception  chaining >  Single-­‐‑dispatch  generic  functions >  Python  virtual  environments >  The  enum  module >  The  asyncio  module >  And  lots  of  other  new  features Welcome! {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 3. The  super  function {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 4. class SilentDict(dict): def __getitem__(self, key): """Called to implement evaluation of self[key] :returns: None by default """ try: return super(SilentDict, self).__getitem__(key) except KeyError: return None >>> d = SilentDict() >>> print (d[“a”]) None >>> d = SilentDict({"a": 1, "b": 2}) >>> print(d["a"]) 1 >>> print(d["a"]) None Let’s  implement  a  SilentDict {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 5. class SilentDict(dict): def __getitem__(self, key): """Called to implement evaluation of self[key] :returns: None by default """ try: return super().__getitem__(key) except KeyError: return None >>> d = SilentDict() >>> print (d[“a”]) None >>> d = SilentDict({"a": 1, "b": 2}) >>> print(d["a"]) 1 >>> print(d["a"]) None Let’s  implement  a  SilentDict {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 6. >  h5p://docs.python.org/3/library/ functions.html#super >  PEP  3135:  New  Super >  >  h5p://www.python.org/dev/peps/pep-­‐‑3135/ Introduced  in  Python  3.0 >  Standard  Library  updated  to  use  it >  No  official  backport The  super  function {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 7. The  yield  from  statement {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 8. Let’s  implement  itertools.chain {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 9. def chain(*iterables): # chain('ABC', 'DEF') --> A B C D E F for it in iterables: yield from it >>> list(chain('ABC', 'DEF')) ['A', 'B', 'C', 'D', 'E', 'F'] >>> list(chain([1, 2, 3], (4, 5, 6), [7, 8, 9])) [1, 2, 3, 4, 5, 6, 7, 8, 9] Let’s  implement  itertools.chain {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 10. >  PEP  380:  Syntax  for  Delegating  to  a  Subgenerator >  h5p://www.python.org/dev/peps/pep-­‐‑0380/ >  Introduced  in  Python  3.3 >  No  backport The  yield  from  statement {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 11. The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 12. from urllib.request import urlopen from urllib.error import URLError class CustomException(Exception): """Out custom exception for this example""” def requester(url): """Open and read given url""" try: return urlopen(url).readall() except URLError: raise CustomException def call_the_requester(url): return requester(url) def main_app(url): print(call_the_requester(url)) if __name__ == "__main__": main_app("http://unknown_host:8765") The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 13. $ python3.4 raise_from_none_examples.py Traceback (most recent call last): ... File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/urllib/ request.py", line 1255, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known> During handling of the above exception, another exception occurred: Traceback (most recent call last): File "raise_from_none_examples.py", line 39, in <module> main_app("http://unknown_host:8765") File "raise_from_none_examples.py", line 35, in main_app print(call_the_requester(url)) File "raise_from_none_examples.py", line 31, in call_the_requester return requester(url) File "raise_from_none_examples.py", line 27, in requester raise CustomException __main__.CustomException The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 14. $ python3.4 raise_from_none_examples.py Traceback (most recent call last): ... File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/urllib/ request.py", line 1255, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known> During handling of the above exception, another exception occurred: Traceback (most recent call last): File "raise_from_none_examples.py", line 39, in <module> main_app("http://unknown_host:8765") File "raise_from_none_examples.py", line 35, in main_app print(call_the_requester(url)) File "raise_from_none_examples.py", line 31, in call_the_requester return requester(url) File "raise_from_none_examples.py", line 27, in requester raise CustomException __main__.CustomException The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 15. from urllib.request import urlopen from urllib.error import URLError class CustomException(Exception): """Out custom exception for this example""” def requester(url): """Open and read given url""" try: return urlopen(url).readall() except URLError as exc: raise CustomException from exc def call_the_requester(url): return requester(url) def main_app(url): print(call_the_requester(url)) if __name__ == "__main__": main_app("http://unknown_host:8765") The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 16. $ python3.4 raise_from_none_examples.py Traceback (most recent call last): ... File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/ request.py", line 1242, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known> The above exception was the direct cause of the following exception: Traceback (most recent call last): File "raise_from_none_examples.py", line 40, in <module> main_app("http://unknown_host:8765") File "raise_from_none_examples.py", line 36, in main_app print(call_the_requester(url)) File "raise_from_none_examples.py", line 32, in call_the_requester return requester(url) File "raise_from_none_examples.py", line 28, in requester raise CustomException from exc __main__.CustomException The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 17. from urllib.request import urlopen from urllib.error import URLError class CustomException(Exception): """Out custom exception for this example""” def requester(url): """Open and read given url""" try: return urlopen(url).readall() except URLError: raise CustomException from None def call_the_requester(url): return requester(url) def main_app(url): print(call_the_requester(url)) if __name__ == "__main__": main_app("http://unknown_host:8765") The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 18. $ python3.4 raise_from_none_examples.py Traceback (most recent call last): File "raise_from_none_examples.py", line main_app("http://unknown_host:8765") File "raise_from_none_examples.py", line print(call_the_requester(url)) File "raise_from_none_examples.py", line call_the_requester return requester(url) File "raise_from_none_examples.py", line raise CustomException from None __main__.CustomException 40, in <module> 36, in main_app 32, in 28, in requester The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 19. >  Several  PEPs  involved: >  PEP  3134:  Exception  Chaining  and  Embedded   Tracebacks >  >  PEP  409:  Suppressing  exception  context >  >  h5p://www.python.org/dev/peps/pep-­‐‑3134 h5p://www.python.org/dev/peps/pep-­‐‑0409/ PEP  415:  Implement  context  suppression  with   exception  a5ributes >  h5p://www.python.org/dev/peps/pep-­‐‑0415 >  Introduced  in  Python  3.0  and  3.3 >  No  official  backport The  new  exception  chaining {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 20. Single-­‐‑dispatch  generic  functions {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 21. class Duck: def quack(self): print("quack") class Cat: def meow(self): print("meow") class Dog: def bark(self): print("bark”) class Cow: def moo(self): print("moo") donald = Duck() garfield = Cat() milu = Dog() milka = Cow() Let’s  create  some  animals {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 22. def make_sound(animal): if isinstance(animal, Duck): animal.quack() elif isinstance(animal, Cat): animal.meow() elif isinstance(animal, Dog): animal.bark() else: raise NotImplementedError("Unknown animal") >>> make_sound(donald) quack >>> make_sound(garfield) meow >>> make_sound(milu) bark >>> make_sound(milka) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 11, in make_sound NotImplementedError: Unknown animal Let’s  play  animals’  sounds {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 23. import functools @functools.singledispatch def make_sound(animal): raise NotImplementedError("Unknown animal") @make_sound.register(Duck) def make_duck_sound(animal): animal.quack() @make_sound.register(Cat) def make_cat_sound(animal): animal.meow() @make_sound.register(Dog) def _(animal): animal.bark() Single-­‐‑dispatch  generic  functions {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 24. >>> make_sound(donald) quack >>> make_sound(garfield) meow >>> make_sound(milu) bark >>> make_sound(milka) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/ python3.4/functools.py", line 632, in wrapper return dispatch(args[0].__class__)(*args, **kw) File "<stdin>", line 5, in make_sound NotImplementedError: Unknown animal Single-­‐‑dispatch  generic  functions {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 25. >  h5p://docs.python.org/dev/library/ functools.html#functools.singledispatch >  PEP  443:  Single-­‐‑dispatch  generic  functions >  >  >  h5p://www.python.org/dev/peps/pep-­‐‑0443/ Introduced  in  Python  3.4 No  official  backport Single-­‐‑dispatch  generic  functions {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 26. Python  virtual  environments {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 27. $ pyvenv /tmp/test_venv $ ls /tmp/test_venv/ bin include lib pyvenv.cfg $ ls /tmp/test_venv/bin/ activate activate.csh activate.fish python python3 python3.4 $ cat /tmp/test_venv/pyvenv.cfg home = /Library/Frameworks/Python.framework/Versions/3.4/bin include-system-site-packages = false version = 3.4.0 $ pyvenv /tmp/test_venv --symlinks --clear --system-site-packages $ cat /tmp/test_venv/pyvenv.cfg home = /Library/Frameworks/Python.framework/Versions/3.4/bin include-system-site-packages = true version = 3.4.0 $ ls -lAhtr /tmp/test_venv/bin/python3.4 lrwxr-xr-x 1 pev wheel 63B 5 nov 00:21 /tmp/test_venv/bin/python3.4 -> / Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 Python  virtual  environments {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 28. $ source /tmp/test_venv/bin/activate (test_venv) ...$ which python /tmp/test_venv/bin/python (test_venv) ...$ which python3.4 /tmp/test_venv/bin/python3.4 (test_venv) ...$ python Python 3.4.0a4 (v3.4.0a4:e245b0d7209b, Oct 20 2013, 02:43:50) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.prefix, sys.base_prefix ('/private/tmp/test_venv', '/Library/Frameworks/Python.framework/Versions/3.4') >>> sys.exec_prefix, sys.base_exec_prefix ('/private/tmp/test_venv', '/Library/Frameworks/Python.framework/Versions/3.4') (test_venv) ...$ deactivate $ which python /usr/bin/python Python  virtual  environments {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 29. >  Features >  Supports  symbolic  links  (recommended) >  Access  both  environment  and  system  site-­‐‑packages   >  pyvenv.cfg  environment  configuration  file: >  >  >  >  home:  path  to  original  Python  installation  bin include-­‐‑system-­‐‑site-­‐‑packages:  access  system  site-­‐‑packages   after  the  environment  site-­‐‑packages version:  Python  version  in  use Public  API  to  let  3rd  party  virtual  environments  customise   the  environment  creation >  Subclass  EnvBuilder  and  redefine  desired  methods Python  virtual  environments {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 30. >  h5p://docs.python.org/3/library/venv.html >  PEP  405:  Python  Virtual  Environments >  >  >  h5p://www.python.org/dev/peps/pep-­‐‑0405/ Introduced  in  Python  3.3 No  official  backport,  although  quite  similar  to   virtualenv Python  virtual  environments {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 31. The  enum  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 32. RED, ORANGE, GREEN = range(3) # Colors STOPPED, RUNNING = range(2) # Statuses class TrafficLight: def __init__(self, light_color, status): assert light_color in (RED, ORANGE, GREEN), "Not a valid color" assert status in (RUNNING, STOPPED), "Not a valid status" self.color = light_color self.status = status def print_state(self): color_name = "red" if self.color == RED else "green" if self.color == GREEN else "orange" status_name = "running" if self.status == RUNNING else "stopped" print("Traffic light is {} in color {}".format(status_name, color_name)) >>> my_semaphore = TrafficLight(RUNNING, RED) >>> my_semaphore.print_state() Traffic light is stopped in color orange Let’s  implement  a  traffic  light {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 33. RED, ORANGE, GREEN = range(3) # Colors STOPPED, RUNNING = range(2) # Statuses class TrafficLight: def __init__(self, light_color, status): assert light_color in (RED, ORANGE, GREEN), "Not a valid color" assert status in (RUNNING, STOPPED), "Not a valid status" self.color = light_color self.status = status def print_state(self): color_name = "red" if self.color == RED else "green" if self.color == GREEN else "orange" status_name = "running" if self.status == RUNNING else "stopped" print("Traffic light is {} in color {}".format(status_name, color_name)) >>> my_semaphore = TrafficLight(RUNNING, RED) >>> my_semaphore.print_state() Traffic light is stopped in color orange Let’s  implement  a  traffic  light {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 34. RED, ORANGE, GREEN = range(3) # Colors STOPPED, RUNNING = range(2) # Statuses class TrafficLight: def __init__(self, light_color, status): assert light_color in (RED, ORANGE, GREEN), "Not a valid color" assert status in (RUNNING, STOPPED), "Not a valid status" self.color = light_color self.status = status def print_state(self): color_name = "red" if self.color == RED else "green" if self.color == GREEN else "orange" status_name = "running" if self.status == RUNNING else "stopped" print("Traffic light is {} in color {}".format(status_name, color_name)) >>> my_semaphore = TrafficLight(RUNNING, RED) >>> my_semaphore.print_state() Traffic light is stopped in color orange Let’s  implement  a  traffic  light {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 35. RED, ORANGE, GREEN = range(3) # Colors STOPPED, RUNNING = range(2) # Statuses class TrafficLight: def __init__(self, light_color, status): assert light_color in (RED, ORANGE, GREEN), "Not a valid color" assert status in (RUNNING, STOPPED), "Not a valid status" self.color = light_color self.status = status def print_state(self): color_name = "red" if self.color == RED else "green" if self.color == GREEN else "orange" status_name = "running" if self.status == RUNNING else "stopped" print("Traffic light is {} in color {}".format(status_name, color_name)) >>> STOPPED is RED and RUNNING is ORANGE True >>> (RUNNING + ORANGE) * GREEN 4 Let’s  implement  a  traffic  light {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 36. from enum import Enum Color = Enum("Color", "red orange green") # Colors Status = Enum("Status", "stopped running") # Statuses class TrafficLight: def __init__(self, light_color, status): assert light_color in Color, "Not a valid color" assert status in Status, "Not a valid status" self.color = light_color self.status = status def print_state(self): color_name = "red" if self.color == Color.red else "green" if self.color == Color.green else "orange" status_name = "running" if self.status == Status.running else "stopped" print("Traffic light is {} in color {}".format(status_name, color_name)) my_semaphore = TrafficLight(Status.running, Color.red) Introducing  the  enum  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 37. >>> my_semaphore = TrafficLight(Status.running, Color.red) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in __init__ AssertionError: Not a valid color >>> my_semaphore = TrafficLight(Color.red, Status.running) >>> my_semaphore.print_state() Traffic light is running in color red >>> Status.stopped is Color.red False >>> Status.running is Color.orange False >>> (Status.running + Color.orange) * Color.green Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'Status' and 'Color' Introducing  the  enum  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 38. class Color(Enum): # enumaration red = 0 orange = 10 # enumeration members green = 20 # custom non-consecutive values ruby = 0 # aliases >>> print(Color.green) Color.green >>> print(repr(Color.green)) <Color.green: 20> >>> print(repr(Color.ruby)) # this is an alias <Color.red: 0> >>> print(Color.orange.name) # we can retrieve a member name orange >>> print(Color["orange"]) # we can get the enum member from its name Color.orange >>> print(Color.orange.value) # we can retrieve a member value 10 >>> print(Color(10)) # we can get the enum member from its value Color.orange More  about  enum  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 39. class Color(Enum): red = 0 orange = 10 green = 20 class Status(Enum): running = 0 stopped = 1 class TrafficLight: def __init__(self, light_color, status): assert light_color in Color, "Not a valid color" assert status in Status, "Not a valid status" self.color = light_color self.status = status def print_state(self): print("Traffic light is {} in color {}".format(self.status.name, self.color.name)) >>> my_semaphore = TrafficLight(Color.red, Status.running) >>> my_semaphore.print_state() Traffic light is running in color red More  about  enum  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 40. >  And  still  more  features >  Iteration  over  enumeration  members >  >  Ordered  dictionary  __members__  special  a5ribute Define  methods  and  class  methods >  Even  redefine  __str__  or  __repr__ >  IntEnum  to  preserve  old  int  behaviour >  @enum.unique  to  enforce  no  aliases  are  defined >  Possibility  to  define  other  custom  Enum  sublcasses >  Functional  API More  about  enum  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 41. >  h5p://docs.python.org/3.4/library/enum.html >  PEP  435:  Adding  an  Enum  type  to  the  Python   standard  library >  >  >  h5p://www.python.org/dev/peps/pep-­‐‑0435/ Introduced  in  Python  3.4 Standard  Library  updated  to  use  enums >  >  >  IntEnum  when  backwards-­‐‑compatibility  broken Enum  in  new  developments  and  internal  modules Official  backport  available  in  PyPi >  h5ps://pypi.python.org/pypi/enum34/   The  enum  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 42. The  asyncio  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 43. >  Python’s  asynchronous  IO  Support  Rebooted >  No  new  language  features,  no  new  lib  extensions >  Based  on  a  customisable  event  loop >  Interface  to  manage  the  event  loop  and  its  policies >  Interface  to  implement  or  adapt  event  loops >  Different  3rd  party  async  frameworks  could  interoperate >  Coroutines,  futures  and  tasks >  Transports  and  protocols >  Use  yield  from  to  delegate  or  callbacks The  asyncio  module  (aka.  Tulip) {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 44. >  h5p://docs.python.org/3.4/library/enum.html >  PEP  3156:  Asynchronous  IO  Support  Rebooted:   the  "ʺasyncio"ʺ  Module >  h5p://www.python.org/dev/peps/pep-­‐‑3156/ >  >  >  Reference  implementation  in  Python  3.4 Expected  final  status  in  Python  3.5 Backport  to  3.3  available  in  PyPi >  h5ps://pypi.python.org/pypi/asyncio/0.1.1 The  asyncio  module {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 45. >  unicode,  unicode  everywhere >  generators,  generators  everywhere >  or  iterators >  uniNest.mock  (port  of  Michael  Foord’s  mock) >  contextlib.ExitStack  and  contextlib.ContextDecorator >  Be5er  GIL  (but  still  Global  Interpreter  Lock) >  concurrent.futures  for  async  computation >  Qualified  name  for  classes  and  functions >  selectors  module >  … And  still  lots  of  new  features {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 46. Q&A {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 47. Are  we  done  yet? Q&A {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 48. Are  we  done  yet? >  Not  yet >  Only  22  slides  missing >  16  only  with  pictures,  and  even  1  animated  GIF >  Sorry,  no  ki5ens Q&A {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 49. Should  we  move  now  to   Python  3? Q&A {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 50. Should  we  move  now  to   Python  3? >  YES >  Well,  maybe  NO >  Well,  let  me  explain Q&A {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 51. h5p://www.python.org/download/releases/2.7/ Release  schedule: >  … >  2.7.0  final:  July  3,  2010 >  … >  2.7.6  candidate  1:  October  26,  2013 >  ??? >  2.7.X  end  of  support:  ≈  2016 Python  2.7 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 52. h5p://www.python.org/download/releases/3.4.0/ Release  schedule: >  3.4.0  alpha  4:  October  20,  2013 >  3.4.0  beta  1  (feature  freeze):  November  24,  2013 >  3.4.0  beta  2:  January  5,  2014 >  3.4.0  candidate  1:  January  19,  2014 >  3.4.0  candidate  2:  February  2,  2014 >  3.4.0  final:  February  23,  2014 Python  3.4 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 53. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 54. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 55. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 56. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 57. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 58. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 59. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 60. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 61. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 62. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 63. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 64. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 65. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 66. The  long  journey  to  Python  3 {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 67. Meanwhile,  most  of  the  community {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 68. >  Great  features  are  waiting  us  in  Python  3 >  We  are  beyond  half  the  planned  life  of  Python  2.7 >  >  Most  3rd  party  dependencies  already  in  Python  3 >  >  Python  2.6  is  officially  retired  with  2.6.9  release Or  we  could  return  to  OSS  all  that  we  have  been  given Porting  to  Python  3  is  not  such  a  big  deal >  In  most  of  the  cases >  So,  no  more  excuses >  It’s  time  to  start  moving  to  Python  3 Conclusions {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 69. Conclusions {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}
  • 70. Thanks  for  coming! Slides:  h5p://goo.gl/Yrzt0Q   Code:  h5p://goo.gl/V9bv72   Q&A {  “event”:  “PDI  DEVCON  2013”,  “author”:  “Pablo  Enfedaque”,  “twi5er”:  “pablitoev56”}