SlideShare a Scribd company logo
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 Minimal redundancy
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: Consistency with console input (also a function)
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)

More Related Content

What's hot (20)

PPTX
Introduction to python
MaheshPandit16
 
PPTX
Python basics
Jyoti shukla
 
PDF
Python Tutorial
AkramWaseem
 
PPT
Python ppt
Rohit Verma
 
PPTX
Python basics
RANAALIMAJEEDRAJPUT
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PPTX
Python 3 Programming Language
Tahani Al-Manie
 
PPTX
Python ppt
Rachit Bhargava
 
PPTX
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
PPT
Python Programming Language
Dr.YNM
 
PDF
Python Loop
Soba Arjun
 
PPTX
Python Session - 2
AnirudhaGaikwad4
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PPTX
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
PPT
Python ppt
Mohita Pandey
 
PPTX
Learning Python - Week 2
Mindy McAdams
 
ODP
Python Presentation
Narendra Sisodiya
 
PDF
Zero to Hero - Introduction to Python3
Chariza Pladin
 
PPTX
Python Seminar PPT
Shivam Gupta
 
Introduction to python
MaheshPandit16
 
Python basics
Jyoti shukla
 
Python Tutorial
AkramWaseem
 
Python ppt
Rohit Verma
 
Python basics
RANAALIMAJEEDRAJPUT
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Python 3 Programming Language
Tahani Al-Manie
 
Python ppt
Rachit Bhargava
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
Python Programming Language
Dr.YNM
 
Python Loop
Soba Arjun
 
Python Session - 2
AnirudhaGaikwad4
 
Fundamentals of Python Programming
Kamal Acharya
 
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
Python ppt
Mohita Pandey
 
Learning Python - Week 2
Mindy McAdams
 
Python Presentation
Narendra Sisodiya
 
Zero to Hero - Introduction to Python3
Chariza Pladin
 
Python Seminar PPT
Shivam Gupta
 

Viewers also liked (7)

PPTX
Next generation web protocols
Daniel Austin
 
ODP
Technology of the future
Irene
 
PPSX
Future Technology
Cartridge Service
 
PPT
Future Technologies Presentation
anthony librarian
 
PPT
Future Of Technology
Melanie Swan
 
PPTX
Future technology
Vigneshwara Lingam
 
PPT
Technology powerpoint presentations
ismailraesha
 
Next generation web protocols
Daniel Austin
 
Technology of the future
Irene
 
Future Technology
Cartridge Service
 
Future Technologies Presentation
anthony librarian
 
Future Of Technology
Melanie Swan
 
Future technology
Vigneshwara Lingam
 
Technology powerpoint presentations
ismailraesha
 
Ad

Similar to Moving to Python 3 (20)

PPT
Os Vanrossum
oscon2007
 
PPT
Python 3000
Alexandro Colorado
 
PPTX
Python PPT by Sushil Sir.pptx
sushil155005
 
DOC
Python 2 vs Python 3 Key Differences.doc
TCCI Computer Coaching
 
PPT
Python Evolution
Quintagroup
 
ODP
Programming Under Linux In Python
Marwan Osman
 
PPTX
A deep dive into python and it's position in the programming landscape.pptx
Murugan Murugan
 
ODP
Introduction to Python
tswr
 
PPT
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
admin369652
 
PPTX
Python-Yesterday Today Tomorrow(What's new?)
Mohan Arumugam
 
PDF
What is python
EU Edge
 
PPTX
What is Python?
PranavSB
 
PDF
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
PDF
Python tour
Tamer Abdul-Radi
 
PPT
Python
Kumar Gaurav
 
PPT
1-ppt-python.ppt
ssusera99a83
 
PPTX
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
Prof. Wim Van Criekinge
 
PPT
Python for students step by step guidance
MantoshKumar79
 
PPT
Introduction to Python For Diploma Students
SanjaySampat1
 
Os Vanrossum
oscon2007
 
Python 3000
Alexandro Colorado
 
Python PPT by Sushil Sir.pptx
sushil155005
 
Python 2 vs Python 3 Key Differences.doc
TCCI Computer Coaching
 
Python Evolution
Quintagroup
 
Programming Under Linux In Python
Marwan Osman
 
A deep dive into python and it's position in the programming landscape.pptx
Murugan Murugan
 
Introduction to Python
tswr
 
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
admin369652
 
Python-Yesterday Today Tomorrow(What's new?)
Mohan Arumugam
 
What is python
EU Edge
 
What is Python?
PranavSB
 
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
Python tour
Tamer Abdul-Radi
 
Python
Kumar Gaurav
 
1-ppt-python.ppt
ssusera99a83
 
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
Prof. Wim Van Criekinge
 
Python for students step by step guidance
MantoshKumar79
 
Introduction to Python For Diploma Students
SanjaySampat1
 
Ad

Recently uploaded (20)

PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 

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. Desirable Language Attributes Minimal redundancy
  • 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. Conceptual Consistency: I/O In Python 2, print is a statement In Python 3, it is a function Benefits: Consistency with console input (also a function)
  • 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. So Python 3... Is less redundant
  • 26. Time To Change? Python 3 has matured to the point where it is now ‘production-ready’
  • 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. A Helpful Tool: 2to3 Distributed with Python 3
  • 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. Obstacles Support from third-party libraries & frameworks – ‘chicken & egg’ situation
  • 35. Availability of books, online tutorials, etc
  • 36. Running multiple Python versions alongside each other is a pain ( virtualenv helps a lot)