Discover Python 3 Slavek Kabrda Presented by

Slides:



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

Python 3000 (PyCon, 24-Feb-02007) Guido van Rossum
Python 3000 and You Guido van Rossum PyCon March 14, 2008.
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
Bruce Beckles University of Cambridge Computing Service
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Python Control of Flow.
Exceptions COMPSCI 105 S Principles of Computer Science.
Advanced Inheritance Concepts. In this chapter, we will cover: Creating and using abstract classes Using dynamic method binding Creating arrays of subclass.
WEEK EXCEPTION HANDLING. Syntax Errors Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while.
Debugging and Interpreting Exceptions UW CSE 190p Summer 2012.
Functions. Built-in functions You’ve used several functions already >>> len("ATGGTCA")‏ 7 >>> abs(-6)‏ 6 >>> float("3.1415")‏ >>>
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
Namespace, scope, compile time activities, runtime activities When do the small integer values get stored in RAM? How did the names in the builtin namespace.
Cem Sahin CS  There are two distinguishable kinds of errors: Python's Errors Syntax ErrorsExceptions.
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)
+ Ruby and other programming Languages Ronald L. Ramos.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Debugging and Printing George Mason University. Today’s topics Review of Chapter 3: Printing and Debugging Go over examples and questions debugging in.
LECTURE 2 Python Basics. MODULES So, we just put together our first real Python program. Let’s say we store this program in a file called fib.py. We have.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Today… Strings: –String Methods Demo. Raising Exceptions. os Module Winter 2016CISC101 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
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.
Rajkumar Jayachandran.  Classes for python are not much different than those of other languages  Not much new syntax or semantics  Python classes are.
Python 3.0 (Py3K) Introduction Authors:timchen119.nospam.at.gmail.com ( 使徒提姆 ) Location: Taiwan COSCUP 2008 Date: 2008/08/24 Blog:
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Python 3000.
Advanced Python Idioms
Lecture 2 Python Basics.
Introduction to Python
Computer Programming Fundamentals
IF statements.
Tutorial Lecture for EE562 Artificial Intelligence for Engineers
Functions CIS 40 – Introduction to Programming in Python
Writing Code to run on Python 2.x and 3.x
Exception Handling.
Python’s Errors and Exceptions
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Passing Parameters by value
ERRORS AND EXCEPTIONS Errors:
CSC1018F: Intermediate Python
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Python Functions Part I Presented by : Sharmin Abdullah
Python Syntax Errors and Exceptions
CISC101 Reminders All assignments are now posted.
Advanced Inheritance Concepts
Advanced Python Idioms
CISC101 Reminders Assignment 2 due today.
Advanced Python Idioms
Test Automation For Web-Based Applications
COMPUTER PROGRAMMING SKILLS
By Ryan Christen Errors and Exceptions.
Functions So far we've been using functions from the builtin module, which is automatically loaded in most cases. Occasionally we've accessed functions.
Functions Functions being objects means functions can be passed into other functions: sort (list, key=str.upper)
CISC101 Reminders Assignment 3 due today.
Object-Oriented Design AND CLASS PROPERTIES
© Sangeeta M Chauhan, Gwalior
LING/C SC/PSYC 438/538 Lecture 7 Sandiway Fong.
Presentation transcript:

Discover Python 3 Slavek Kabrda Presented by Senior Software Engineer, Red Hat CC-BY-SA 3.0

Agenda What? Python 3? What's new? Porting Fedora 22: Python 3 as Default (?) Q & A, discussion

What? Python 3?

https://twitter.com/ncoghlan_dev/status/487250116433039360 Python 3: the programming language the creators of Python 2 prefer to use :) Nick Coghlan @ twitter https://twitter.com/ncoghlan_dev/status/487250116433039360

Python 3 is... Also known as Python 3000 or Py3k Not fully compatible with Python 2.x But you can write code that runs on both More Pythonic The present and future of the Python language

What's Different? (1/6) Print is no longer statement from __future__ import print_function print 'foo' => print('foo')

What's Different? (2/6) dict.has_key('foo') => 'foo' in dict dict.iter<what>() => dict.<what>() dict.<what>() => list(dict.<what>()) For <what> in ['keys', 'values', 'items']

What's Different? (3/6) basestring => no longer exists str => bytes unicode => str long/int => int

What's Different? (4/6) map(), filter() and zip() return iterators range()/xrange() => range()

What's Different? (5/6) except MyException, foo => except MyException as foo

What's Different? (6/6) import foo => always absolute To import from current package, use relative import: from . import foo

And more... Renamed/split libraries (configparser, urllib, ...) New IO library No cmp() No `12` Changes in C bindings Iterators ...

What's new? a.k.a “Python 3 Goodies”

Keyword Only Arguments PY2: def foo(a, b, beep=False, explode=False) foo(1, 2, True) PY3: def foo(a, b, *, beep=False, explode=False) foo(1, 2, True) => TypeError foo(1, 2, beep=True) => correct Prevents: accidental passing of more arguments errors when reordering arguments Helps get rid of **kwargs in some situations

Chained Exceptions raise SomeException from e Allows chaining tracebacks => preserves the original error

Advanced Unpacking first, *x, last = file.readlines() *zero_to_eight, nine = range(10)

Matrix Multiplication Coming in Python 3.5 http://legacy.python.org/dev/peps/pep-0465/ c = a @ b a @= b

Type Hinting Also coming in Python 3.5 (arbitrary annotations were added in 3.0) Specification still not 100 % ready https://www.python.org/dev/peps/pep-0484/ def foo(x: int, y: str) -> str: return y * x

Subgenerators yield from other_generator() yield from range(10) yield from afile.readlines()

And more... asyncio (I don't pretend to understand it, but it's cool) faulthandler ipaddress, pathlib enum (!) Fine grained OSError subclasses (Almost) Everything is an iterator No more funny comparisons 'abc' > 42 => TypeError

Porting

How to Port? Decide if you want to keep backwards compatibility If yes, don't go bellow Python 2.6 (RHEL 5 anyone?) Ideally, port to 3.3+ Good test coverage is a must Useful tools: 2to3 python-modernize python-six Other tools like pyflakes, pep8, ...

Resources https://docs.python.org/3/howto/pyporting.html https://docs.python.org/3/howto/cporting.html http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/ http://python3porting.com/ http://www.wefearchange.org/2011/12/lessons-in-porting-to-python-3.html https://pythonhosted.org/six/ https://wiki.gnome.org/action/show/Projects/PyGObject/IntrospectionPorting http://overtag.dk/wordpress/2013/01/first-impressions-of-gtk3-migration-in- python/ https://bkabrda.fedorapeople.org/discover-python3.odp bkabrda@redhat.com

Fedora 22 – Python 3 as Default

Or not

Libraries vs. Applications Something that other libraries/applications import Applications Something that users run

It means ... We now prefer Python 3 for applications We'll almost get rid of Python 2 from Workstation LiveCD We'll have Python 3 only in minimal cloud image and atomic host It doesn't mean ... Dropping Python 2 Forcing people to write downstream-only patches Pointing /usr/bin/python to python3

Helping out

We'll Need Your Help Again! http://fedoraproject.org/wiki/Changes/Python_3_as_Default https://fedoraproject.org/wiki/User:Churchyard/python3 These two currently cover Workstation LiveCD and minimal cloud image We'll continue working on Server LiveCD and packager tools for F23 Or anything else that's in Fedora and it's Python 2 only Remember, upstream is first

Questions? Contact: bkabrda@redhat.com http://devconf.cz/f/86