SlideShare a Scribd company logo
10 Reasons to Adopt Python 3
About Me
Pierre Fersing – pierref@bleemeo.com
CTO & co-founder @Bleemeo
Python & Django dev for 10 years
Monitoring as a Service solution
API in Django + User Interface in ReactJS
① Comparison in Python
>>> ["user1", 20] < ["user2", 10]
True
>>> ["user1", 20] < ["user1", 30]
True
① Comparison in Python
Py2 : False !
Py3 : TypeError: unorderable types: tuple() < list()
>>> ("user1", 20) < ["user2", 99]
>>> max("one", 2)
"one"
② Iterators, Iterators Everywhere
Consume about 1,5 GB of memory with Python
2 !
range vs xrange, keys vs iterkeys, values vs
itervalues, items vs iteritems
zip, map, filter
>>> for _ in range(50000000):
... the_answer = 42
③ Keywords Only Arguments
>>> def sortwords(
... words, reverse, case_sensitive):
>>> sortwords(
... ["one", "two", "three"],
... reverse=True, case_sensitive=False)
③ Keywords Only Arguments
>>> def sortwords(
... words, reverse, case_sensitive):
>>> sortwords(
... ["one", "two", "three"], True, False)
>>> def sortwords(
... words, case_sensitive, reverse):
>>> def sortwords(
... words, *, case_sensitive, reverse):
③ Keyword Arguments
>>> sortwords(
... "one", "two", "three",
... case_sensitive=False
... )
>>> def sortwords(*words, **kwargs):
... case_sensitive = 
... kwargs.pop("case_sensitive")
③ Keyword Arguments
>>> sortwords(
... "one", "two", "three",
... case_sensitive=False
... )
>>> def sortwords(
... *words, case_sensitive=True):
④ Improved Except Syntax
>>> try:
... 0 / 0
... except OSError, ZeroDivisionError:
... print("Error")
④ Improved Except Syntax
>>> try:
... 0 / 0
... except (OSError, ZeroDivisionError) as err:
... print("Error")
⑤ Chained Exceptions
>>> try:
... connection = do_connect()
... # do stuff
... finally:
... connection.close()
Traceback (most recent call last):
File "code.py", line 5, in <module>
connection.close()
NameError: name 'connection' is not defined
⑤ Chained Exceptions
Traceback (most recent call last):
File "plop.py", line 2, in <module>
connection = do_connect()
ConnectionRefusedError: [Errno 111]
Connection refused
During handling of the above exception,
another exception occurred:
Traceback (most recent call last):
File "plop.py", line 5, in <module>
connection.close()
NameError: name 'connection' is not defined
⑥ Reworked OS/IO Exception
>>> try:
... fd = open("/etc/shadow")
... except IOError:
... print("Error")
>>> try:
... os.stat("/etc/shadow")
... except OSError:
... print("Error")
⑥ Reworked OS/IO Exception
>>> try:
... fd = open("/etc/shadow")
... except IOError as err:
... if err.errno in (EACCES, EPERM):
... print("Error")
... else:
... raise
⑥ Reworked OS/IO Exception
>>> try:
... fd = open("/etc/shadow")
... except PermissionError:
... print("Error")
⑦ Reworked Stdlib Names
Which module ? urllib, urllib2, urlparse ?
– Parsing an url : urlparse
– Quoting an URL : urllib
– Do a requests : urllib2
No more cPickle, cProfile, cStringIO
⑧ Stdlib Additions
>>> etc = pathlib.Path("/etc")
... file = etc / "passwd"
... file.read_text()
>>> @functools.lru_cache(max_size=32)
... def expansive_function(params):
⑧ Stdlib Additions
>>> subprocess.run(
... ["ls", "-l"], timeout=10)
>>> datetime.now().timestamp()
>>> secrets.token_urlsafe()
⑧ Stdlib Additions
Lots more :
– lzma
– enum
– ipaddress
– faulthandler
– statistics
– ...
⑨ asyncio and async/await
>>> reader,writer = await asyncio.open_connection(
... "www.python.org", 80)
... writer.write(b'GET / […]')
... async for line in reader:
... # do something with the line
⑩ Bonus
>>> 1 / 2
0.5
>>> for x in iterable:
... yield x
>>> yield from iterable
⑩ Bonus
Tab-completion in interpreter
>>> class Children(Parent):
... def method(self):
... super().method()
⑩ Bonus
>>> round(1.5)
2
>>> round(2.5)
2
Question ?

More Related Content

PDF
Créer une api publique avec Django REST framework
PPTX
Introduction to Guzzle
PDF
PSR-7 - HTTP message interfaces
PDF
PSR-7 and PSR-15, why can't you ignore them
PDF
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
PDF
MongoDB shell games: Here be dragons .. and JavaScript!
PDF
PyCon Taiwan 2013 Tutorial
PDF
ExtJS勉強会@名古屋
Créer une api publique avec Django REST framework
Introduction to Guzzle
PSR-7 - HTTP message interfaces
PSR-7 and PSR-15, why can't you ignore them
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
MongoDB shell games: Here be dragons .. and JavaScript!
PyCon Taiwan 2013 Tutorial
ExtJS勉強会@名古屋

Viewers also liked (20)

DOCX
Temas de pensamiento administrativo 2 corte
PPTX
Evaluating unconciousness in icu
PPTX
La evolución de las comunicaciones
PDF
MY PORT 30.11.16
PPTX
Gaining &amp; maintaining access to stigmatized samples (revised final)-6-1-15
DOCX
Semiótica
PPTX
Contaminación aire y agua
PDF
Monitoring in the Cloud Era
PDF
Votre infrastructure est élastique, et votre monitoring ?
PPTX
Descubrir la brecha digital en México
DOCX
Alimentación balanceada
PPTX
Dalmo taxa selic
DOCX
Pensamiento administrativo (1)
PPTX
Contaminación
PDF
CSP068-6 BRO ENG A4 CS Solutions (1)
PPTX
Jhonatan alcaldia
DOCX
Temas de administracion 3 corte
PPTX
Presentation on PD- Ravi Bhatt
PPTX
Strategic Purchasing Supply Initiatives
PPTX
Presentación de Milagros Talí
Temas de pensamiento administrativo 2 corte
Evaluating unconciousness in icu
La evolución de las comunicaciones
MY PORT 30.11.16
Gaining &amp; maintaining access to stigmatized samples (revised final)-6-1-15
Semiótica
Contaminación aire y agua
Monitoring in the Cloud Era
Votre infrastructure est élastique, et votre monitoring ?
Descubrir la brecha digital en México
Alimentación balanceada
Dalmo taxa selic
Pensamiento administrativo (1)
Contaminación
CSP068-6 BRO ENG A4 CS Solutions (1)
Jhonatan alcaldia
Temas de administracion 3 corte
Presentation on PD- Ravi Bhatt
Strategic Purchasing Supply Initiatives
Presentación de Milagros Talí
Ad

Similar to 10 reasons to adopt Python 3 (20)

PDF
Porting to Python 3
PDF
Porting to Python 3
PDF
Pycon taiwan 2018_claudiu_popa
KEY
State of Python (2010)
PDF
Why Python 3
PPTX
Porting a legacy app to python 3
PDF
Intro to Python
PPTX
Python material
PDF
Intermediate python
PPTX
Introduction to python programming 1
PDF
25 must know python for Interview by Tutort Academy
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
PDF
The two flavors of Python 3.13 - PyHEP 2024
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
KEY
What's New In Python 2.5
PDF
What's new in Python 3.11
PDF
30 hidden gems_in_python_3
DOC
Python 2 vs Python 3 Key Differences.doc
PDF
Comparison between Python 2 and Python 3
Porting to Python 3
Porting to Python 3
Pycon taiwan 2018_claudiu_popa
State of Python (2010)
Why Python 3
Porting a legacy app to python 3
Intro to Python
Python material
Intermediate python
Introduction to python programming 1
25 must know python for Interview by Tutort Academy
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
The two flavors of Python 3.13 - PyHEP 2024
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
What's New In Python 2.5
What's new in Python 3.11
30 hidden gems_in_python_3
Python 2 vs Python 3 Key Differences.doc
Comparison between Python 2 and Python 3
Ad

Recently uploaded (20)

PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Tartificialntelligence_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Mushroom cultivation and it's methods.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Encapsulation theory and applications.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Group 1 Presentation -Planning and Decision Making .pptx
Approach and Philosophy of On baking technology
Tartificialntelligence_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Web App vs Mobile App What Should You Build First.pdf
TLE Review Electricity (Electricity).pptx
Mushroom cultivation and it's methods.pdf
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation_ Review paper, used for researhc scholars
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
OMC Textile Division Presentation 2021.pptx
A comparative analysis of optical character recognition models for extracting...
WOOl fibre morphology and structure.pdf for textiles
Encapsulation theory and applications.pdf
Enhancing emotion recognition model for a student engagement use case through...
NewMind AI Weekly Chronicles - August'25-Week II

10 reasons to adopt Python 3

  • 1. 10 Reasons to Adopt Python 3
  • 2. About Me Pierre Fersing – pierref@bleemeo.com CTO & co-founder @Bleemeo Python & Django dev for 10 years
  • 3. Monitoring as a Service solution API in Django + User Interface in ReactJS
  • 4. ① Comparison in Python >>> ["user1", 20] < ["user2", 10] True >>> ["user1", 20] < ["user1", 30] True
  • 5. ① Comparison in Python Py2 : False ! Py3 : TypeError: unorderable types: tuple() < list() >>> ("user1", 20) < ["user2", 99] >>> max("one", 2) "one"
  • 6. ② Iterators, Iterators Everywhere Consume about 1,5 GB of memory with Python 2 ! range vs xrange, keys vs iterkeys, values vs itervalues, items vs iteritems zip, map, filter >>> for _ in range(50000000): ... the_answer = 42
  • 7. ③ Keywords Only Arguments >>> def sortwords( ... words, reverse, case_sensitive): >>> sortwords( ... ["one", "two", "three"], ... reverse=True, case_sensitive=False)
  • 8. ③ Keywords Only Arguments >>> def sortwords( ... words, reverse, case_sensitive): >>> sortwords( ... ["one", "two", "three"], True, False) >>> def sortwords( ... words, case_sensitive, reverse): >>> def sortwords( ... words, *, case_sensitive, reverse):
  • 9. ③ Keyword Arguments >>> sortwords( ... "one", "two", "three", ... case_sensitive=False ... ) >>> def sortwords(*words, **kwargs): ... case_sensitive = ... kwargs.pop("case_sensitive")
  • 10. ③ Keyword Arguments >>> sortwords( ... "one", "two", "three", ... case_sensitive=False ... ) >>> def sortwords( ... *words, case_sensitive=True):
  • 11. ④ Improved Except Syntax >>> try: ... 0 / 0 ... except OSError, ZeroDivisionError: ... print("Error")
  • 12. ④ Improved Except Syntax >>> try: ... 0 / 0 ... except (OSError, ZeroDivisionError) as err: ... print("Error")
  • 13. ⑤ Chained Exceptions >>> try: ... connection = do_connect() ... # do stuff ... finally: ... connection.close() Traceback (most recent call last): File "code.py", line 5, in <module> connection.close() NameError: name 'connection' is not defined
  • 14. ⑤ Chained Exceptions Traceback (most recent call last): File "plop.py", line 2, in <module> connection = do_connect() ConnectionRefusedError: [Errno 111] Connection refused During handling of the above exception, another exception occurred: Traceback (most recent call last): File "plop.py", line 5, in <module> connection.close() NameError: name 'connection' is not defined
  • 15. ⑥ Reworked OS/IO Exception >>> try: ... fd = open("/etc/shadow") ... except IOError: ... print("Error") >>> try: ... os.stat("/etc/shadow") ... except OSError: ... print("Error")
  • 16. ⑥ Reworked OS/IO Exception >>> try: ... fd = open("/etc/shadow") ... except IOError as err: ... if err.errno in (EACCES, EPERM): ... print("Error") ... else: ... raise
  • 17. ⑥ Reworked OS/IO Exception >>> try: ... fd = open("/etc/shadow") ... except PermissionError: ... print("Error")
  • 18. ⑦ Reworked Stdlib Names Which module ? urllib, urllib2, urlparse ? – Parsing an url : urlparse – Quoting an URL : urllib – Do a requests : urllib2 No more cPickle, cProfile, cStringIO
  • 19. ⑧ Stdlib Additions >>> etc = pathlib.Path("/etc") ... file = etc / "passwd" ... file.read_text() >>> @functools.lru_cache(max_size=32) ... def expansive_function(params):
  • 20. ⑧ Stdlib Additions >>> subprocess.run( ... ["ls", "-l"], timeout=10) >>> datetime.now().timestamp() >>> secrets.token_urlsafe()
  • 21. ⑧ Stdlib Additions Lots more : – lzma – enum – ipaddress – faulthandler – statistics – ...
  • 22. ⑨ asyncio and async/await >>> reader,writer = await asyncio.open_connection( ... "www.python.org", 80) ... writer.write(b'GET / […]') ... async for line in reader: ... # do something with the line
  • 23. ⑩ Bonus >>> 1 / 2 0.5 >>> for x in iterable: ... yield x >>> yield from iterable
  • 24. ⑩ Bonus Tab-completion in interpreter >>> class Children(Parent): ... def method(self): ... super().method()