Title Center for Coastal and Ocean Mapping NOAA/UNH Joint Hydrographic Center 31-Oct-2006 A Python Tutorial Kurt Schwehr 31 Oct 2006
Where is python on my machine?
Fink for unix software
Fink Commander
Emacs Cheat Sheet
Setting up ~/.emacs
Getting started
Strings
Getting help with the ‘tab’ key
More string operations
Lists are created with [ ]
The math module
Getting help on functions
More help
from math import *
The Decimal module
Converting between strings and numbers
If tests and indentation matters
for loops
Reading a file Adding a comma prevents the extra new line
Reading numbers from a file
A quick intro to time
Getting to the web documentation
Writing data to a file
Old school - gnuplot
Gnuplot in 3D
Saving gnuplot to gif or pdf
Writing a python file (aka module) env finds python in your path chmod +x dump.py./dump.py
Handling programs in a better way __name__ is set to main if the file is being executed
Making our code a proper function
Function parameters can be specified by name
Use this function from outside the file Whoops - no documentation!
Often it is good to give a parameter a default
Add some ‘doc strings’
Documentation as seen from ipython
Epydoc is Kurt’s favorite way to document python code Epydoc imports your file and creates html documentation
Here is the initial edydoc page Nice, but could be better Use markups in the doc string to tell epydoc more
Adding more to the file
Document the function