SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
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 ?

Contenu connexe

En vedette

Temas de pensamiento administrativo 2 corte
Temas de pensamiento administrativo 2 corteTemas de pensamiento administrativo 2 corte
Temas de pensamiento administrativo 2 cortewilder yepes
 
Evaluating unconciousness in icu
Evaluating unconciousness in icuEvaluating unconciousness in icu
Evaluating unconciousness in icunss115
 
La evolución de las comunicaciones
La evolución de las comunicacionesLa evolución de las comunicaciones
La evolución de las comunicacionesRita Veron
 
Gaining &amp; maintaining access to stigmatized samples (revised final)-6-1-15
Gaining &amp; maintaining  access to stigmatized samples (revised final)-6-1-15Gaining &amp; maintaining  access to stigmatized samples (revised final)-6-1-15
Gaining &amp; maintaining access to stigmatized samples (revised final)-6-1-15dcprojectconnect
 
Contaminación aire y agua
Contaminación aire y agua Contaminación aire y agua
Contaminación aire y agua Luz Millan
 
Monitoring in the Cloud Era
Monitoring in the Cloud EraMonitoring in the Cloud Era
Monitoring in the Cloud EraBleemeo
 
Votre infrastructure est élastique, et votre monitoring ?
Votre infrastructure est élastique, et votre monitoring ?Votre infrastructure est élastique, et votre monitoring ?
Votre infrastructure est élastique, et votre monitoring ?Bleemeo
 
Descubrir la brecha digital en México
Descubrir la brecha digital en MéxicoDescubrir la brecha digital en México
Descubrir la brecha digital en MéxicoEdith Suarez
 
Pensamiento administrativo (1)
Pensamiento administrativo (1)Pensamiento administrativo (1)
Pensamiento administrativo (1)wilder yepes
 
Contaminación
ContaminaciónContaminación
ContaminaciónLuz Millan
 
CSP068-6 BRO ENG A4 CS Solutions (1)
CSP068-6 BRO ENG A4 CS Solutions (1)CSP068-6 BRO ENG A4 CS Solutions (1)
CSP068-6 BRO ENG A4 CS Solutions (1)Carlos G. Silva
 
Temas de administracion 3 corte
Temas de administracion 3 corteTemas de administracion 3 corte
Temas de administracion 3 cortewilder yepes
 
Presentation on PD- Ravi Bhatt
Presentation on PD- Ravi BhattPresentation on PD- Ravi Bhatt
Presentation on PD- Ravi BhattRavi Bhatt
 
Strategic Purchasing Supply Initiatives
Strategic Purchasing Supply InitiativesStrategic Purchasing Supply Initiatives
Strategic Purchasing Supply Initiativesignasuhe
 
Presentación de Milagros Talí
Presentación de Milagros TalíPresentación de Milagros Talí
Presentación de Milagros TalíMilagros Talí
 

En vedette (20)

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

Similaire à 10 reasons to adopt Python 3

Python Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-FinallyPython Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-FinallyVinod Srivastava
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
Zope component architechture
Zope component architechtureZope component architechture
Zope component architechtureAnatoly Bubenkov
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in pythonjunnubabu
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanWei-Yuan Chang
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applicationsRoman Podoliaka
 
Server discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDBServer discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDBJoe Drumgoole
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Edureka!
 
Erlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The UglyErlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The Uglyenriquepazperez
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181Mahmoud Samir Fayed
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fpAlexander Granin
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184Mahmoud Samir Fayed
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesTatiana Al-Chueyr
 
Python Network Programming – Course Applications Guide
Python Network Programming – Course Applications GuidePython Network Programming – Course Applications Guide
Python Network Programming – Course Applications GuideMihai Catalin Teodosiu
 

Similaire à 10 reasons to adopt Python 3 (20)

Python Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-FinallyPython Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-Finally
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Zope component architechture
Zope component architechtureZope component architechture
Zope component architechture
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in python
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp KrennJavantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
 
Python 3
Python 3Python 3
Python 3
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Server discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDBServer discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDB
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
 
Erlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The UglyErlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The Ugly
 
Tuning Java Servers
Tuning Java Servers Tuning Java Servers
Tuning Java Servers
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fp
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
Python Network Programming – Course Applications Guide
Python Network Programming – Course Applications GuidePython Network Programming – Course Applications Guide
Python Network Programming – Course Applications Guide
 

Dernier

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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()