What is Python?

26
What is Python? Wesly Chun, Google IO 2011 May 11, 2011 Wesly Chun, Google IO 2011 What is Python?

Transcript of What is Python?

Page 1: What is Python?

What is Python?

Wesly Chun, Google IO 2011

May 11, 2011

Wesly Chun, Google IO 2011 What is Python?

Page 2: What is Python?

About Guido van Rossum

Creator of Python (BDFL)

Software Engineer at Google

Google App Engine

Python libraries, API designUI programming, developer tools

22+ years of Python

Wesly Chun, Google IO 2011 What is Python?

Page 3: What is Python?

Python in a Nutshell

General-purpose programming language

Object-oriented

Scripting or mission-critical servers

Interpreted but bytecode-compiled

Simple yet robust syntax

Easy-to-read, -learn, -maintain

Batteries included

Wesly Chun, Google IO 2011 What is Python?

Page 4: What is Python?

Python is now twenty!

Wesly Chun, Google IO 2011 What is Python?

Page 5: What is Python?

Gains in popularity

Jump in job listings

Safari Top 5 Queries, Apr 2009

iPhoneJavaPythonC#PHP

Source: Safari Books Online (O’Reilly, Pearson)

Wesly Chun, Google IO 2011 What is Python?

Page 6: What is Python?

Fan Favorite

Tiobe Language of the Year (2010, 2007)

www.tiobe.comAlternates between #6 and #7 (vs. Objective-C)

LinuxJournal

Favorite Programming Language (2010, 2009)Favorite Scripting Language (2010, 2008, 2007, 2006)linuxjournal.com

LinuxQuestions.org Members Choice Awards

Language of the Year (2010, 2009, 2008, 2007)linuxquestions.org

Wesly Chun, Google IO 2011 What is Python?

Page 7: What is Python?

Gaining more mindshare

Google App Engine announcement

Launches with PythonParts of Django framework

Change at MIT

Switches from Scheme to PythonFocuses on RoboticsMITx: 6.00x Introduction to Computer Science andProgramming at edx.org

Learn how to write programs that solve problemsSkill can be transferred to any programming language

Think Python: How to think like a computer scientist

Ability to formulate problems, think creatively about solutions,and express a solution clearly and accuratelyhttp://www.greenteapress.com/thinkpython/

Wesly Chun, Google IO 2011 What is Python?

Page 8: What is Python?

Python & Education

Heavily inspired by ABC

Simplistic yet robust syntax

Computer Programming for Everybody (CP4E)

Programming as a basic skill

High School Success Story

Computer Science Advanced Placement ExamPython helped with retention/understanding

interactivepython.org

pythontutor.com

Wesly Chun, Google IO 2011 What is Python?

Page 9: What is Python?

Programming Languages

Adults: tools to get work done

C/C++/C#, Java, PHP, Python, Ruby

Kids: used to teach programming

Scratch, Alice, Python, Basic, Flash/AS

Conclusion: if made for kids...

Wesly Chun, Google IO 2011 What is Python?

Page 10: What is Python?

Demo

1 def foo ():

2 factor = 10

3 try:

4 f = open(’data.txt’, ’w’)

5 except IOError as e:

6 print ’file open error’, e

7 return

8

9 for i in range (10): # (int i=0; i<10; i++)

10 print >> f, i + factor ,

11 if i % 2 == 0:

12 print >> f, ’even’

13 else:

14 print >> f, ’odd’

15 f.close ()

Wesly Chun, Google IO 2011 What is Python?

Page 11: What is Python?

Demo (improved version)

1 def foo ():

2 factor = 10

3 with open(’data.txt’, ’w’) as f:

4 for i in range (10):

5 if i % 2 == 0:

6 num = ’even’

7 else:

8 num = ’odd’

9 # old string formatting

10 # f.write ("%d, %s\n" % (i+factor , num))

11

12 f.write("{0}, {1}\n".format(i+factor , num))

Wesly Chun, Google IO 2011 What is Python?

Page 12: What is Python?

Output

data.txt

10 , even11 , odd12 , even13 , odd14 , even15 , odd16 , even17 , odd18 , even19 , odd

Wesly Chun, Google IO 2011 What is Python?

Page 13: What is Python?

Well-known projects

NumPy, SciPy, Matplotlib

Jython, IronPython, PyPy

virtualenv

SQLAlchemy

nose, py.test

windmill, Selenium

BeautfilSoup, html5lib, lxml

IPython, bpython

Sphinx, ReportLab

Python Extensios for Windows

Wesly Chun, Google IO 2011 What is Python?

Page 14: What is Python?

NumPy, SciPy & Matplotlib example

1 import numpy

2 import scipy.special

3 import matplotlib.pyplot as mpl

4 # compute Bezzel function

5 x, y = numpy.mgrid [ -25:25:100j, -25:25:100j]

6 r = numpy.sqrt(x**2 + y**2)

7 B = scipy.special.j0(r)

8 # now do plotting

9 mpl.contourf(x, y, B)

10 mpl.colorbar ()

11 mpl.show()

Wesly Chun, Google IO 2011 What is Python?

Page 15: What is Python?

Web frameworks

Django

TurboGears, Pylons, repoze.bfg, Pyramid

web2py

web.py

Google App’s Engine webapp

Werkzeug, Flask, Tipfy

Zope, Plone

Tornado

etc.

”Python: the only language with more web frameworks thatkeywords.”

Harald Armin Massa, 2005groups.google.com/group/comp.lang.python/msg

Wesly Chun, Google IO 2011 What is Python?

Page 16: What is Python?

Python used for...

Networking

Web/RIA apps

QA/testing, automation frameworks

Text Processing

Database Programming

Scientific, mathematical/numeric processing

Hardware/embedded system design

Multimedia, graphics/imaging, animation

GUI development

Java, .NET, COM/MFC

Batteries included

Wesly Chun, Google IO 2011 What is Python?

Page 17: What is Python?

Python @ ???

Google

Yahoo!

Dropbox

Disney, Pixar, Dreamworks

Lucas: Lucasfilm, ILM, LucasArts

VMware, Broadcom, QNX

Evite, eventbrite, Justin.tv

Yelp, Tripit, Zillow, Netflix

Red Hat, Ubuntu/Canonical, OLPC, Raspberry Pi

NASA, NOAA (NWS), NSA

etc.

Wesly Chun, Google IO 2011 What is Python?

Page 18: What is Python?

Python and Google

An official language

Can deploy to production servers

C++ primary development language

Need for systems/scripting language

Java came later

Wesly Chun, Google IO 2011 What is Python?

Page 19: What is Python?

History @ Google

Use of Python before company founded

”In order to scale hundreds of millions of web pages, Googlehas a fast distributed crawling system. A single URLserverserves... URLs to a number of crawlers... Both the URLserverand the crawlers are implemented in Python.”

From ”Anatomy of a Large-Scale Hypertextual Web SearchEngine”S. Brin & L. Page, Stanford University, 1998infolab.stanford.edu/ backrub/google.html

Wesly Chun, Google IO 2011 What is Python?

Page 20: What is Python?

Another quote

”Python has been an important part of Google since thebeginning, and remains so as the system grows and evolves.”

– Peter Norvig, Director of Research at Google

Wesly Chun, Google IO 2011 What is Python?

Page 21: What is Python?

Products using Python

Google App Engine

YouTube (flexibility, rapid development, simplicity)

code.google.com

Various open source libraries

Wesly Chun, Google IO 2011 What is Python?

Page 22: What is Python?

Other uses of Python

Build system

System administration tools

Monitoring, managing systemsLog anaylsisReport generation

Code review tool

QA/testing

Automation

Extensive use of SWIG

App Engine apps

Wesly Chun, Google IO 2011 What is Python?

Page 23: What is Python?

Two versions of Python

Python 2: current version

Python 3: next generation

Language evolving

Backwards-incompatible

Insert FUD here

No community fragmentation

Wesly Chun, Google IO 2011 What is Python?

Page 24: What is Python?

Hello World (again)

Python 2.x

1 print ’Hello World!’

Python 3.x

1 print (’Hello World!’)

Or use the standard file methods

1 import sys

2 sys.stdout.write(’Hello World!\n’)

Wesly Chun, Google IO 2011 What is Python?

Page 25: What is Python?

Which to start with?

Python 3.x: next generation

Do this if completely new

Python 2.x: current version

Most books/tutorials still hereDo this if have existing software

Bottom-line: either is fine

Wesly Chun, Google IO 2011 What is Python?

Page 26: What is Python?

That’s all folks

Wesly Chun, Google IO 2011 What is Python?