SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Moving To Python 3 Why? When? How? Nick Efford (http://about.me/nickefford)
Backwards Compatibility An ‘unwritten law’ of software... ...and yet Python 3 breaks it – so badly that “Hello World!” no longer works! $ python3 hello.py File "hello.py", line 1 print 'Hello World!' ^ SyntaxError: invalid syntax Why?
Compatibility Isn’t Free... Java is bloated because obsolete features are never removed
Python’s Brave Decision "The language has two choices: either continue to bear the burden of what are now considered poor design decisions... or suck it up and let us try and fix some of these problems. It's like going to the dentist; it may hurt, but if that minor toothache goes untreated and develops into an abscess, you will wish you were dead." –  blog entry by Collin Winter
Desirable Language Attributes ,[object Object]
Maximal separation of concerns
Minimal surprise
Conceptual consistency
Appropriate complexity
Redundancy: Iteration in Java for (int i = 0; i < message.length(); ++i) { System.out.println(message.charAt(i)); } for (int i = 0; i < messageChars.length; ++i) { System.out.println(messageChars[i]); } 2 different ‘classic’ syntaxes for iterating over strings & arrays...
Redundancy: Iteration in Java for (int i = 0; i < vec.size(); ++i) { System.out.println(vec.elementAt(i)); } for (int i = 0; i < vec.size(); ++i) { System.out.println(vec.get(i)); } Enumeration<Integer> enumerator = vec.elements(); while (enumerator.hasMoreElements()) { System.out.println(enumerator.nextElement()); } Iterator<Integer> iterator = vec.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } ...+ 4 for vectors...
Redundancy: Iteration in Java for (int number : vec) { System.out.println(number); } for (char character : messageChars) { System.out.println(character); } ...+ 2 newer approaches for vectors & arrays...
Redundancy: Iteration in Java // Before JDK 1.5 BufferedReader inputFile = new BufferedReader( new FileReader(&quot;foo.txt&quot;)); String line = inputFile.readLine(); while (line != null) { System.out.println(line); line = inputFile.readLine(); } // Since JDK 1.5 Scanner inputFile = new Scanner(new File(&quot;foo.txt&quot;)); while (inputFile.hasNextLine()) { System.out.println(inputFile.nextLine()); } ...+ 2 for text files  =  10 different iteration syntaxes!
Redundancy: Iteration in Python for character in string: print character for number in numbers: print number input_file = open('foo.txt') for line in input_file: print line, One syntax  works for strings, lists and text files!
Redundancy: Integer Representation Java: four primitive integer types, four corresponding wrapper classes,  BigInteger  class Python 2: two integer types –  int  &  long Python 3: one integer type –  int
Redundancy: Object Model Two types of class in Python 2: class Foo: ... class Bar(object): ... Only ‘new-style’ classes exist in Python 3 (either syntax can be used) ‘old-style’ class ‘new-style’ class
Redundancy: Console Input Python 2 has  two  functions providing console input: raw_input , yielding input as a string input , yielding the result of calling  eval  on input Python 3 has one function,  input , with the same behaviour as Python 2’s  raw_input (New programmers also find this less surprising...)
Conceptual Consistency: I/O In Python 2,  print  is a statement In Python 3, it is a  function Benefits: ,[object Object]
Greater flexibility provided by keyword arguments print(text, file=output_file)   print(x, y, z, sep=':')
Minimal Surprise: Integer Division >>> 5 / 3 1.6666666666666667 >>> 5 // 3 1 Python 3 >>> 5 / 3 1 Python 2 (like C, C++, Java – but unlike proper arithmetic)

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python basics
Python basicsPython basics
Python basics
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Python ppt
Python pptPython ppt
Python ppt
 
Python basics
Python basicsPython basics
Python basics
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Python ppt
Python pptPython ppt
Python ppt
 
Python
PythonPython
Python
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Python Loop
Python LoopPython Loop
Python Loop
 
Python Session - 2
Python Session - 2Python Session - 2
Python Session - 2
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
 
Python ppt
Python pptPython ppt
Python ppt
 
Learning Python - Week 2
Learning Python - Week 2Learning Python - Week 2
Learning Python - Week 2
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 

Andere mochten auch (7)

Next generation web protocols
Next generation web protocolsNext generation web protocols
Next generation web protocols
 
Technology of the future
Technology of the futureTechnology of the future
Technology of the future
 
Future Technology
Future TechnologyFuture Technology
Future Technology
 
Future Technologies Presentation
Future Technologies PresentationFuture Technologies Presentation
Future Technologies Presentation
 
Future Of Technology
Future Of  TechnologyFuture Of  Technology
Future Of Technology
 
Future technology
Future technologyFuture technology
Future technology
 
Technology powerpoint presentations
Technology powerpoint presentationsTechnology powerpoint presentations
Technology powerpoint presentations
 

Ähnlich wie Moving to Python 3

Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
gabriellekuruvilla
 

Ähnlich wie Moving to Python 3 (20)

Python Evolution
Python EvolutionPython Evolution
Python Evolution
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptx
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdf
 
The Onward Journey: Porting Twisted to Python 3
The Onward Journey: Porting Twisted to Python 3The Onward Journey: Porting Twisted to Python 3
The Onward Journey: Porting Twisted to Python 3
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
python presentation
python presentationpython presentation
python presentation
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
 
Learn python
Learn pythonLearn python
Learn python
 
Python 3000
Python 3000Python 3000
Python 3000
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course Basic
 
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for Bioinformatics
 

Kürzlich hochgeladen

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
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
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...
 
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...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Moving to Python 3

  • 1. Moving To Python 3 Why? When? How? Nick Efford (http://about.me/nickefford)
  • 2. Backwards Compatibility An ‘unwritten law’ of software... ...and yet Python 3 breaks it – so badly that “Hello World!” no longer works! $ python3 hello.py File &quot;hello.py&quot;, line 1 print 'Hello World!' ^ SyntaxError: invalid syntax Why?
  • 3. Compatibility Isn’t Free... Java is bloated because obsolete features are never removed
  • 4. Python’s Brave Decision &quot;The language has two choices: either continue to bear the burden of what are now considered poor design decisions... or suck it up and let us try and fix some of these problems. It's like going to the dentist; it may hurt, but if that minor toothache goes untreated and develops into an abscess, you will wish you were dead.&quot; – blog entry by Collin Winter
  • 5.
  • 10. Redundancy: Iteration in Java for (int i = 0; i < message.length(); ++i) { System.out.println(message.charAt(i)); } for (int i = 0; i < messageChars.length; ++i) { System.out.println(messageChars[i]); } 2 different ‘classic’ syntaxes for iterating over strings & arrays...
  • 11. Redundancy: Iteration in Java for (int i = 0; i < vec.size(); ++i) { System.out.println(vec.elementAt(i)); } for (int i = 0; i < vec.size(); ++i) { System.out.println(vec.get(i)); } Enumeration<Integer> enumerator = vec.elements(); while (enumerator.hasMoreElements()) { System.out.println(enumerator.nextElement()); } Iterator<Integer> iterator = vec.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } ...+ 4 for vectors...
  • 12. Redundancy: Iteration in Java for (int number : vec) { System.out.println(number); } for (char character : messageChars) { System.out.println(character); } ...+ 2 newer approaches for vectors & arrays...
  • 13. Redundancy: Iteration in Java // Before JDK 1.5 BufferedReader inputFile = new BufferedReader( new FileReader(&quot;foo.txt&quot;)); String line = inputFile.readLine(); while (line != null) { System.out.println(line); line = inputFile.readLine(); } // Since JDK 1.5 Scanner inputFile = new Scanner(new File(&quot;foo.txt&quot;)); while (inputFile.hasNextLine()) { System.out.println(inputFile.nextLine()); } ...+ 2 for text files = 10 different iteration syntaxes!
  • 14. Redundancy: Iteration in Python for character in string: print character for number in numbers: print number input_file = open('foo.txt') for line in input_file: print line, One syntax works for strings, lists and text files!
  • 15. Redundancy: Integer Representation Java: four primitive integer types, four corresponding wrapper classes, BigInteger class Python 2: two integer types – int & long Python 3: one integer type – int
  • 16. Redundancy: Object Model Two types of class in Python 2: class Foo: ... class Bar(object): ... Only ‘new-style’ classes exist in Python 3 (either syntax can be used) ‘old-style’ class ‘new-style’ class
  • 17. Redundancy: Console Input Python 2 has two functions providing console input: raw_input , yielding input as a string input , yielding the result of calling eval on input Python 3 has one function, input , with the same behaviour as Python 2’s raw_input (New programmers also find this less surprising...)
  • 18.
  • 19. Greater flexibility provided by keyword arguments print(text, file=output_file) print(x, y, z, sep=':')
  • 20. Minimal Surprise: Integer Division >>> 5 / 3 1.6666666666666667 >>> 5 // 3 1 Python 3 >>> 5 / 3 1 Python 2 (like C, C++, Java – but unlike proper arithmetic)
  • 21. Separation of Concerns: Text vs Binary Data Python 2: str for ASCII text strings & byte strings unicode for Unicode strings Two representations of text, overlapping with one for binary data! Python 3: str for Unicode text strings bytes for strings of bytes Clean separation of text and binary representations, with encode & decode methods for conversion
  • 22.
  • 26.
  • 27. Development of the Python 2 line has come to an end with Python 2.7 (apart from bug fixes)
  • 28. Focus for future innovation will be Python 3 (notwithstanding Jython, IronPython, PyPy, etc)
  • 29.
  • 30. Converts Python 2 code to Python 3
  • 31. Integrates with D istutils and can run during installation, allowing you to support 2 & 3 from one codebase
  • 32. Cannot do a perfect job; you may need more unit tests and may have to refactor your code a bit
  • 33. Only handles Python code; C extensions need to be converted to Python 3 API by hand
  • 34.
  • 35. Availability of books, online tutorials, etc
  • 36. Running multiple Python versions alongside each other is a pain ( virtualenv helps a lot)