4. Tim Penhey
Otago University Comp Sci 19911994
Intermittent contractor for 12 years
Started working for Canonical over 2 years ago
First started with Python 8 years ago after
reading “The Cathedral & the Bazaar”
Python has been my primary development
language for around three years now
4
5. 5
6. Quick Question
What languages are you tought as an
undergraduate now?
When I was here we did: Pascal; Modula2;
LISP; Prolog; Assembly; C; Haskell; ML; Ada;
and Objective C (kinda)
6
13. Guido van Rossum
Python's BDFL
http://www.python.org/~guido/
Blog http://neopythonic.blogspot.com/
Now works for Google
13
14. Python History
Implementation started Dec 1989
Feb 1991 released to alt.sources
Jan 1994 1.0.0 released
Oct 2000 2.0 released
Oct 2008 2.6 released
Dec 2008 3.0 released
2.7 and 3.1 in development
14
16. Python has...
very high level dynamic data types
an extensive standard libraries and third party
modules for virtually every task
extensions and modules easily written in C,
C++ (or Java for Jython, or .NET languages for
IronPython)
the ability to be embedded within applications
as a scripting interface
16
17. Python plays well with others
Python can integrate with COM, .NET, and
CORBA objects
Jython is Python for the JVM and can interact
fully with Java classes
IronPython is Python for .NET
Well supported in the Internet Communication
Engine (ICE http://zeroc.com)
17
18. Python runs everywhere
All major operating systems
Windows
Linux/Unix
Mac
And some lesser ones
OS/2
Amiga
Nokia Series 60 cell phones
18
19. Python is Open
Implemented under an open source license
Freely usable and distributable, even for
commercial use.
Python Enhancement Proposals – PEP
propose new features
collecting community input
documenting decisions
19
20. My Python Favourites #1
The Zen of Python
PEP 20
Long time Pythoneer Tim Peters succinctly
channels the BDFL's guiding principles for Python's
design into 20 aphorisms, only 19 of which have
been written down.
aphorism – A tersely phrased statement of a
truth or opinion
20
42. Datatypes
All the usual suspects
Strings (Unicode)
int
bool
float (only one real type)
complex
files
42
43. Unusual Suspects
long — automatic promotion from int if needed
>>> x = 1024
>>> x ** 50
327339060789614187001318969682759915221
664204604306478948329136809613379640467
455488327009232590415715088668412756007
1009217256545885393053328527589376L
43
45. Functions
Python uses whitespace to determine blocks of
code (please don't use tabs)
def greet(person):
if person == “Tim”:
print “Hello Master”
else:
print “Hello %s” % person
45
46. Parameter Passing
Order is important unless using the name
def foo(name, age, address)
foo('Tim', address='Home', age=36)
Default arguments are supported
def greet(name='World')
Variable length args acceptable as a list or dict
def foo(*args, **kwargs)
46
48. Modules
Any python file is considered a module
Modules are loaded from the PYTHONPATH
Nested modules are supported by using
directories.
~/src/lazr/enum/__init__.py
If PYTHONPATH includes ~/src
import lazr.enum
48
49. Exceptions
Also used for flow control – StopIteration
Exceptions are classes, and custom exceptions
are easy to write to store extra state information
raise SomeException(params)
try:
# Do stuff
except Exception, e:
# Do something else
finally:
49
# Occurs after try and except block
50. Duck Typing
If it walks like a duck and quacks like a duck, I
would call it a duck – James Whitcomb Riley
There is no function or method overriding
Methods can be checked using getattr
Consider zope.interface
50
51. Batteries Included
The Python standard library is very extensive
regular expressions, codecs
date and time, collections, theads and mutexs
OS and shell level functions (mv, rm, ls)
Support for SQLite and Berkley databases
zlib, gzip, bz2, tarfile, csv, xml, md5, sha
logging, subprocess, email, json
httplib, imaplib, nntplib, smtplib
and much, much more
51
54. Other Domains
Asynchronous Network Programming
Twisted framework http://twistedmatrix.com
Scientific and Numeric
Bioinformatics biopython
Linear algebra, signal processing – SciPy
Fast compact multidimensional arrays – NumPy
Desktop GUIs
wxWidgets, GTK+, Qt
54
55. What is Python bad at?
Anything that requires a lot of mathmatical
computations
Anything that wants to use threads across
cores or CPUs
Realtime systems
55
56. Work arounds
Write extension libraries in C or C++
Use multiple processes instead of multiple
threads
Use a different language
56
57. NZ Python Users Group
http://nzpug.org
Regional meetings, DunPUG
Mailing list using google groups
Planning KiwiPyCon
2 day event over a weekend in Christchurch
78 November 2009 (that's this year!)
57