%deffont "title" tfont "../fonts/trebuc.ttf" %deffont "standard" tfont "../fonts/verdana.ttf" %deffont "thick" tfont "../fonts/GARA.TTF" %default 1 leftfill, size 3, fore "white", back "black", font "thick" %tab 1 size 4, vgap 25, prefix " ", icon arc "blue" 20 %tab 2 size 4, vgap 50, prefix " ", icon arc "red" 20 %%%tab 3 size 5, vgap 50, prefix " ", icon box "red" 50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %bquality 10 %size 7, font "title", fore "white", vgap 20 %center Python Introduction %size 2, font "standard" There once was man named Guido %size 3 Biology Dept, Duke University Hunter Matthews thm@duke.edu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 %center This page accidentally left blank. %size 4, font "standard", fore "white", vgap 10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 What is Python? %size 4, font "standard", fore "white", vgap 10 Scripting language (as opposed to compiled, like C) Object Oriented or Procedural Very High Level Mature (created in 1989/1990) Orthogonally designed - IE, languague/syntax designed all at once Based on an earlier teaching language (ABC) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Its a cliche by now... %size 4, font "standard", fore "white", vgap 10 #! /usr/bin/python print "Hello World." Another: #! /usr/bin/python import string import sys pass = open("/etc/passwd") for line in pass.readlines() list = string.split(line, ":") print list[0], "has %s as their shell" % list[6] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Common Uses %size 4, font "standard", fore "white", vgap 10 Anything a scripting language would be good for... CGI/Web programming (ZOPE, XMLrpc) Systems Administration (most redhat tools, up2date) Large Applications (google, AT&T backbone monitoring, Yahoo) Large amount of number crunching code (Numerical Python/Biopython) No one has written a filesystem yet.... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 What's different about Python %size 4, font "standard", fore "white", vgap 10 Controversial use of indentation for statement grouping. (See next \ slide) Guido has stated specifically that this reduces programmer freedom \ in formatting, leading (he claims) to more readable code. Emphasis of readability and maintainability are priorities. Batteries Included - Perl has more add-ons, python has more included \ in the base. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Detailed Indentation Example %size 4, font "standard", fore "white", vgap 10 class foo(object): def __init__(self, x=1): object.__init__(self) self.x = x def method1(self, bar): if bar == "x": print "got an x" else: print "didn't get no x" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Basics %size 4, font "standard", fore "white", vgap 10 strings, numbers, objects are just names: foo = "This is a string" x = 55 file = open("/etc/passwd") for x in list_of_stuff: print x Wasn't sure what to put here - ask questions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Composite Types %size 4, font "standard", fore "white", vgap 10 Lists: [], ["foo", "bar", 55] Tuples: (), ("bar", "qux", 108] Dictionaries/Hashes: {}, {"key": 55, "2ndkey": 100} Easy Composition: foo = {"key": (a, b, c), "bkey": [1, 2, 3, [1, 2]]} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Python programs are built up from modules. %size 4, font "standard", fore "white", vgap 10 import sys Grabs all the (public) parts of the sys module, and makes them \ available as sys.exit() or sys.argv[] from sys import * Allows developer to simply call exit(), but this is probably \ less common than the other style. Nothing required for user creation of a module - the file name \ with the ".py" removed, if any. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Modules continued %size 4, font "standard", fore "white", vgap 10 Modules can contain classes, functions, or both. Packages are collections of modules Create a dir, add __init__.py, and poof, its a package. Python does not have any kind of "private", "protected" keywords, \ but anything begining with "_" is not imported. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 I claim complex data structures in python are easier %size 4, font "standard", fore "white", vgap 10 From Programming Perl, 2e, p271 Print a hash of hashes: foreach $record (keys(%hash_of_hashs)) { print "record $record:\n"; foreach $field (keys %{$hash_of_hashs{$record}}) { print " $field = %hash_of_hashs{$record}{$field}\n"; } print "\n"; } Equivalent Python code: for record in hash_of_hashs.keys(): print "record:", record for field in hash_of_hashs[record].keys(): print " %s = %s " % field, hash_of_hashes[record][field] print %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Which doesn't stop the module writers.. %size 4, font "standard", fore "white", vgap 10 Database modules (mysql, postgres, sqlite, Oracle) GUI modules (pyGTK, pyGnome, pyqt, wx, tk) Network (twisted framework, SOAP) XML (all 3 and 4 letter acronyms are now XML modules) Crypto, LDAP, file formats, Optik %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Performance Improvements %size 4, font "standard", fore "white", vgap 10 Psycho -- The Python Specializing Compiler (JIT comes to python) There's also pyrex, but I don't like it as much Extending -- Performance critical parts of your program can be \ written in C. Mod_python -- python and apache to crush your network IDLE and pdb -- Improves programmer performance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Changes in python 2 and 2.2 %size 4, font "standard", fore "white", vgap 10 new object model iterators and generators completions changes in division, int/long unification Unicode All of which can be safely ignored. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Strange python genera %size 4, font "standard", fore "white", vgap 10 Python on VMS (vax), MVS/VM, and windows CE Python for your pilot Python compatibility for java - Jython Stackless python (may not be current) You can embed python in your program %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Hunter's python bookshelf %size 3, font "standard", fore "white", vgap 10 THE python book - New Riders "Python Essential Reference" Python documentation from the web site is actually VERY good. Download to laptop and take it with you. The only decent O'Reilly book is the pocket reference. Wake up Tim, New Riders is eating your lunch. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Resources %size 3, font "standard", fore "white", vgap 10 The home page of all things pythonic http://www.python.org Python Quick Reference - everything you need, on one page. http://www.brunningonline.net/simon/python/PQR.html David Beazley's Python Slides http://innerpeace.org/pythonguide.htm Tons of Python apps, modules for python, etc http://www.freshmeat.net Python.faqts http://www.faqts.com/knowledge_base \ /index.phtml/fid/199/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Resources %size 3, font "standard", fore "white", vgap 10 Writing Python Extensions http://starship.python.net/crew/arcege \ /extwriting/pyext.html Starting out python http://www.uselesspython.com/index.html Python Blog http://www.deadlybloodyserious.com/Python Introduction to Numerical Python http://www.onlamp.com/pub/a/python/2000 \ /05/03/numerically.html Psyco (JIT) http://psyco.sourceforge.net %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Resources %size 3, font "standard", fore "white", vgap 10 O'Reillys web site (I don't care for this one) http://www.onlamp.com/python/ Biology and Python http://biopython.org/ All the power of python with all the incompatibility of java. http://www.jython.org/ Daily Python URL http://www.pythonware.com/daily/ Python makes windows suck a little less http://www.python.org/download/ \ download_windows.html %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Resources %size 3, font "standard", fore "white", vgap 10 Python and R (splus) together http://rpy.sourceforge.net/ Python and GTK (and links to pygnome) http://www.daa.com.au/~james/pygtk/ Online Python Journal http://pythonjournal.cognizor.com/ Published (like, as in paper) Python Journal http://www.pyzine.com/ Python Book Reviews -- Bad HTML, great content http://www.awaretek.com/book.html %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %bgrad 0 0 128 90 1 "black" "blue" %size 7, font "title", fore "white", vgap 20 Development is a state of mind. %size 4, font "standard", fore "white", vgap 10 %CENTER #%IMAGE "debugging.jpg" 0 135 135 1 You may ask questions or heckle here.