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 ,[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)

More Related Content

What's hot

Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
MaheshPandit16
 
Python basics
Python basicsPython basics
Python basics
Jyoti shukla
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
AkramWaseem
 
Python ppt
Python pptPython ppt
Python ppt
Rohit Verma
 
Python basics
Python basicsPython basics
Python basics
RANAALIMAJEEDRAJPUT
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
Haitham El-Ghareeb
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie
 
Python ppt
Python pptPython ppt
Python ppt
Rachit Bhargava
 
Python
PythonPython
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)
Paige Bailey
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
Dr.YNM
 
Python Loop
Python LoopPython Loop
Python Loop
Soba Arjun
 
Python Session - 2
Python Session - 2Python Session - 2
Python Session - 2
AnirudhaGaikwad4
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
Python ppt
Python pptPython ppt
Python ppt
Mohita Pandey
 
Learning Python - Week 2
Learning Python - Week 2Learning Python - Week 2
Learning Python - Week 2
Mindy McAdams
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
Narendra Sisodiya
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
Chariza Pladin
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
Shivam Gupta
 

What's hot (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
 

Viewers also liked

Next generation web protocols
Next generation web protocolsNext generation web protocols
Next generation web protocols
Daniel Austin
 
Technology of the future
Technology of the futureTechnology of the future
Technology of the future
Irene
 
Future Technology
Future TechnologyFuture Technology
Future Technology
Cartridge Service
 
Future Technologies Presentation
Future Technologies PresentationFuture Technologies Presentation
Future Technologies Presentation
anthony librarian
 
Future Of Technology
Future Of  TechnologyFuture Of  Technology
Future Of Technology
Melanie Swan
 
Future technology
Future technologyFuture technology
Future technology
Vigneshwara Lingam
 
Technology powerpoint presentations
Technology powerpoint presentationsTechnology powerpoint presentations
Technology powerpoint presentations
ismailraesha
 

Viewers also liked (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 to Moving to Python 3

Python Evolution
Python EvolutionPython Evolution
Python Evolution
Quintagroup
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
zynofustechnology
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptx
sushil155005
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
vishwanathgoudapatil1
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
Dozie Agbo
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
Mukul Kirti Verma
 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdf
Ramakrishna Reddy Bijjam
 
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
Craig Rodrigues
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
samiwaris2
 
python presentation
python presentationpython presentation
python presentation
VaibhavMawal
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
ZENUS INFOTECH INDIA PVT. LTD.
 
Learn python
Learn pythonLearn python
Learn python
Rokibul Islam
 
Python 3000
Python 3000Python 3000
Python 3000
Alexandro Colorado
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
gabriellekuruvilla
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
natnaelmamuye
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
deepak teja
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
Ruth Marvin
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course Basic
Naiyan Noor
 
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for Bioinformatics
José Héctor Gálvez
 

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

Recently uploaded

Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 

Recently uploaded (20)

Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 

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)