SlideShare una empresa de Scribd logo
1 de 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)

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

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

Similar a 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
 

Similar a 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
 

Último

+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@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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, ...
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
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...
 
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...
 
+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...
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

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)