Chapter1 - Introduction to Object-Oriented Programming and Software Development
What is Python?
1. What is Python?
Wesly Chun, Google IO 2011
May 11, 2011
Wesly Chun, Google IO 2011 What is Python?
2. About Guido van Rossum
Creator of Python (BDFL)
Software Engineer at Google
Google App Engine
Python libraries, API design
UI programming, developer tools
22+ years of Python
Wesly Chun, Google IO 2011 What is Python?
3. 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?
4. Python is now twenty!
Wesly Chun, Google IO 2011 What is Python?
5. Gains in popularity
Jump in job listings
Safari Top 5 Queries, Apr 2009
iPhone
Java
Python
C#
PHP
Source: Safari Books Online (O’Reilly, Pearson)
Wesly Chun, Google IO 2011 What is Python?
6. Fan Favorite
Tiobe Language of the Year (2010, 2007)
www.tiobe.com
Alternates 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?
7. Gaining more mindshare
Google App Engine announcement
Launches with Python
Parts of Django framework
Change at MIT
Switches from Scheme to Python
Focuses on Robotics
MITx: 6.00x Introduction to Computer Science and
Programming at edx.org
Learn how to write programs that solve problems
Skill 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 accurately
http://www.greenteapress.com/thinkpython/
Wesly Chun, Google IO 2011 What is Python?
8. 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 Exam
Python helped with retention/understanding
interactivepython.org
pythontutor.com
Wesly Chun, Google IO 2011 What is Python?
9. 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?
10. 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?
11. 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?
12. Output
data.txt
10 , even
11 , odd
12 , even
13 , odd
14 , even
15 , odd
16 , even
17 , odd
18 , even
19 , odd
Wesly Chun, Google IO 2011 What is Python?
13. 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?
14. 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:100 j , -25:25:100 j ]
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?
15. 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 that
keywords.”
Harald Armin Massa, 2005
groups.google.com/group/comp.lang.python/msg
Wesly Chun, Google IO 2011 What is Python?
16. 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?
17. 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?
18. 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?
19. History @ Google
Use of Python before company founded
”In order to scale hundreds of millions of web pages, Google
has a fast distributed crawling system. A single URLserver
serves... URLs to a number of crawlers... Both the URLserver
and the crawlers are implemented in Python.”
From ”Anatomy of a Large-Scale Hypertextual Web Search
Engine”
S. Brin & L. Page, Stanford University, 1998
infolab.stanford.edu/ backrub/google.html
Wesly Chun, Google IO 2011 What is Python?
20. Another quote
”Python has been an important part of Google since the
beginning, and remains so as the system grows and evolves.”
– Peter Norvig, Director of Research at Google
Wesly Chun, Google IO 2011 What is Python?
21. 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?
22. Other uses of Python
Build system
System administration tools
Monitoring, managing systems
Log anaylsis
Report generation
Code review tool
QA/testing
Automation
Extensive use of SWIG
App Engine apps
Wesly Chun, Google IO 2011 What is Python?
23. 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?
24. 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?
25. Which to start with?
Python 3.x: next generation
Do this if completely new
Python 2.x: current version
Most books/tutorials still here
Do this if have existing software
Bottom-line: either is fine
Wesly Chun, Google IO 2011 What is Python?