Python 3000 and You Guido van Rossum EuroPython July 7, 2008.

Slides:



Advertisements
Similar presentations
"The State of the Python Union" Python10 - Alexandria, VA - February 7, 2002 Guido van Rossum Director, PythonLabs at Zope Corporation
Advertisements

State of the Python Union OSCON, July 24, 2002 Guido van Rossum Director of PythonLabs at Zope Corporation
Python 3000 (PyCon, 24-Feb-02007) Guido van Rossum
What's New in Python 2.2 LinuxWorld - New York City - January 2002 Guido van Rossum Director of PythonLabs at Zope Corporation
Python 3000 and You Guido van Rossum PyCon March 14, 2008.
Python 3000 (ACCU Conference / Oxford, UK / April 19, 2006) Guido van Rossum
Python Regrets OSCON, July 25, 2002
EuroPython Keynote June 26, 2002 Guido van Rossum Director of PythonLabs at Zope Corporation
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Container Types in Python
Introduction to Python Week 15. Try It Out! Download Python from Any version will do for this class – By and large they are all mutually.
Bruce Beckles University of Cambridge Computing Service
What's new in Microsoft Visual C Preview
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
1 Exception-Handling Overview Exception: when something unforeseen happens and causes an error Exception handling – improves program clarity by removing.
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Types in programming languages What are types, and why do we need them? Types in programming languages1.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
17. Python Exceptions Handling Python provides two very important features to handle any unexpected error in your Python programs and to add debugging.
Python: Classes By Matt Wufsus. Scopes and Namespaces A namespace is a mapping from names to objects. ◦Examples: the set of built-in names, such as the.
Chapter 24 Exception CSC1310 Fall Exceptions Exceptions Exceptions are events that can modify the flow or control through a program. They are automatically.
Documentation / References Python Full Documentation – Python Quick Reference –
Built-in Data Structures in Python An Introduction.
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
Introduction to Information Security Python. Python motivation Python is to a Hacker what Matlab is to an engineer Lots of built-in modules Lots of 3.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Chapter 14 Advanced Function Topics CSC1310 Fall 2009.
Python Functions.
Python Overview  Last week Python 3000 was released  Python 3000 == Python 3.0 == Py3k  Designed to break backwards compatibility with the 2.x.
Before starting OOP… Today: Review Useful tips and concepts (based on CS 11 Python track, CALTECH)
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
Python Basics. 2 Python History Late 1970s: programming language called ABC at the Centrum voor Wiskunde en Informatica in the Netherlands Audience included.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
16. Python Files I/O Printing to the Screen: The simplest way to produce output is using the print statement where you can pass zero or more expressions,
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
A Tutorial on the Python Programming Language. Overview Running Python and Output Data Types Input and File I/O Control Flow Functions.
Variables, Types, Expressions Intro2CS – week 1b 1.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
Quiz 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
Python Programming Language by Vasu Chetty. Origins of Python Created by: Guido van Rossum, a Dutch Programmer Created during: Christmas Break, 1989 Created.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
FASTFAST All rights reserved © MEP Make programming fun again.
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
Week 13 - Friday.  What did we talk about last time?  Server communications on a socket  Function pointers.
Python 3.0 (Py3K) Introduction Authors:timchen119.nospam.at.gmail.com ( 使徒提姆 ) Location: Taiwan COSCUP 2008 Date: 2008/08/24 Blog:
Swift by Kevin Gamboa Teky Alvarado Hieu Tran Elizabeth Sanchez
Discover Python 3 Slavek Kabrda Presented by
Python 3000.
Introduction to Python
Intro To Pete Alonzi University of Virginia Library
Functional Programming with Java
Introduction to Python
Topics Introduction to File Input and Output
Lecture 2 Python Programming & Data Types
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Lecture 2 Python Programming & Data Types
Python Primer 1: Types and Operators
CISC101 Reminders All assignments are now posted.
COMPUTER PROGRAMMING SKILLS
Topics Introduction to File Input and Output
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Presentation transcript:

Python 3000 and You Guido van Rossum EuroPython July 7, 2008

Why Py3k Open source needs to move or die Matz (creator of Ruby) To fix early, sticky design mistakes e.g. classic classes, int division, print statement Changing times: time/space trade-off e.g. str/unicode, int/long New paradigms come along e.g. dict views, argument annotations

Major Breakages Print function: print(a, b, file=sys.stderr) Distinguish sharply btw. text and data b"…" for bytes literals "…" for (Unicode) str literals Dict keys() returns a set view [+items()/values()] No default, >= implementation 1/2 returns 0.5 Library cleanup and reorganization

Long Anticipated Breakages Kill classic classes Int/long unification Kill string exceptions Exceptions must subclass BaseException Raise syntax: raise Exc(args) [from tb] Except syntax: except Exc as var: Also makes var undefined at block exit

Many Small Breakages Remove cmp() builtin Remove cmp arg to sorted() and list.sort() Kill map(None, …); use zip() map(), filter() return iterators Disallow int(- 1) Explicit relative import Removed `…` Removed <> None, True, False are keywords New keywords as, with, nonlocal raw_input() -> input() xrange() -> range() Changed metaclass syntax Kill compiler package Kill tuple parameters – e.g. def f(a, (b, c)):... New octal literals (0o777).next() ->.__next__(); next() built-in.func_code ->.__code__ Removed dict.has_key() Removed dict.iteritems() etc. Removed sys.maxint; use sys.maxsize Removed reload(); use imp.reload() Removed reduce(); use functools.reduce() Removed apply(); use f(*args) Removed callable(); use Callable ABC Removed basestring; use str.__nonzero__() ->.__bool__() Must override __hash__ when defining __eq__ Module __builtin__ renamed to builtins (no __) Removed many modules, e.g. gopherlib, cfmfile, md5 (use hashlib), mimify (use pkg), and all the MacOS 9 support Etc, etc.

Major New Features, e.g. Argument annotations: def f(a: 2*2, b: 'hello') -> 42: … Abstract Base Classes Extended iterable unpacking: a, b, *x, y = range(5) # 0, 1, [2, 3], 4 New str.format() method: "Got {0} {kind}".format(42, kind='bugs') –"Got 42 bugs"

Many Smaller Improvements I/O no longer depends on C Source code encoding defaults to UTF-8 Allow Unicode letters in names Class decorators __prepare__() method on metaclass Nonlocal statement Keyword-only arguments Default implementation of != negates == Binary literals 0b10101, bin() function Mutable bytes type (bytearray) Overloadable isinstance(), issubclass() fractions.py defines Fraction type super() without arguments Set literals and set comprehensions Dict comprehensions New exception attributes: –__traceback__ –__cause__ (raise from ) –__context__ (when raised in handler) –Exceptions arent sequences; use e.args Abstract Base Classes: –In abc.py: infrastructure –In collections.py: Set, Sequence, Mapping, MutableSet etc. –In numbers.py: Number, Complex, Real, Rational, Integer –In io.py: IOBase and more New modules –e.g. json, multiprocessing Etc, etc.

Whats In It For You More predictable Unicode handling Smaller language Makes Python fits in your brain more true TOOWTDI (Theres Only One Way To Do It -- The Zen of Python) Common traps removed Fewer surprises Fewer exceptions

Enables Future Evolution Examples: –Argument annotations –print() function –str.format() method –Abstract Base Classes –Unicode letters in names

The 2to3 Tool Context-free source code translator Handles syntactic changes best E.g. print; `…`; <>; except E, v: Handles built-ins pretty well E.g. xrange(), apply(), d.keys() Doesnt do type inferencing Doesnt follow variables in your code

When To Switch No hurry! 2.6 will be fully supported Probably 3-5 years or more Release of 2.7 possible, maybe even 2.8 Switch when both of these are true: 1. Youre ready 2. All your dependencies have been ported There are tools to help you switch!

Be Prepared Start writing future-proof code for 2.5 Dont bother with the trivial stuff though: The 2to3 tool will handle this E.g. callable(), `…`, <>, L suffix Instead, focus on what 2to3 cant do: Stop using obsolete modules Start using iterators and generators

Things You Can Do Now Inherit classes from object Use dict.iterkeys() etc. Use xrange(), sorted(), zip() Use // for floor division Inherit exceptions from [Base]Exception Use rich comparisons (__eq__ etc.) Etc., etc.

What About Text Handling There's no silver bullet Isolate handling of encoded text In 2.6: –Use bytes and b'…' for all data Knowing these are just aliases for str and '…' –Use unicode and u'...' for all text In 2.5: '...' for data, u'...' for text

The Role of Python 2.6 Stable, compatible, supported! Many 3.0 features backported But not the new text / data distinction Warns about non-3.0-isms with -3 flag Especially for things that 2to3 can't fix

Transition Strategies If you can: burn your bridges! :-) Otherwise: –Port to 2.6 first –Maintain 2.6 and 3.0 version together –Derive 3.0 version from 2.6 source Using 2to3 whenever you can Using forked code only where you have to –Enables feature parity of your app or lib

Porting C Extensions Fork your code or sprinkle with #ifdef We try to delete APIs or add new ones But not break existing APIs that stay I.e. number & type of arguments won't change 2.6: str, unicode -> PyString, PyUnicode PyBytes is an alias for PyString 3.0: bytes, str -> PyBytes, PyUnicode Also: PyInt vs. PyLong

Release Schedule Releasing 2.6 and in lock step –beta 1: June 18 (just released!) –beta 2: July 15 (coming up next!) –beta 3: August 23 –release candidates: Sept 3, Sept 17 –final release: October 1

I Have This Great Idea… If your idea hasnt made it into 3.0 yet, its definitely too late to get it in Current focus is on: –Fixing bugs –Perfecting backwards compatibility –Improving performance

Wrapping Up Dont fear Py3k! Have fun with the new features Enjoy fewer bugs, traps, surprises Take your time to convert! You will get lots of time, lots of help 2.6 will be stable, compatible, supported For many years to come!

Resources Docs: docs.python.org/dev/3.0/ docs.python.org/dev/3.0/whatsnew/3.0.html Download: python.org/3.0/ PEPs: python.org/dev/peps/pep-3000/ Mailing list: Subversion: svn.python.org/view/python/branches/py3k/