An Introduction to Python

pix
Go back to home page

This page provides an introduction to the Python programming language. A couple of scripts are offered for the task, which can be completed on almost any computer that offers Python.

This page is obsolete.

The latest page is at itmetr.net.

last modified: 05:01 PM MDT, Sun 15 Jun 2008


Learning Python

Most of the tutorials and tasks at this site employ the Python programming language. This site does not provide a Python tutorial, instead you are referred to other sites for that education.

  • I recommend that you start learning Python right here, with these documents on Gentry: A Byte of Python. (You can own that document in either HTML or PDF format by downloading from www.byteofpython.info).

  • Windows users may want to investigate the enthought distribution of Python for Windows.

  • If you plan to use your Python programs in both Windows and Linux, beware of the extra invisible "carriage return" character in Windows text files.

  • One thing that is absolutely cool about Python, as compared with Perl, is the availability of the Integrated Development Environment or IDLE. This should be accessible on Unix/Linux by simple typing idle. If you installed the enthought distro, you can invoke IDLE from the Start menu, e.g. under Python 2.4 (Enthought Edition), you will find IDLE (Python GUI). It is possible to develop and your Python programs entirely within the IDLE window. But what I do is develop Python within my favorite text editor (vim for me) and use the IDLE window to test out short snippets of Python. For example, suppose I forgot how to pop an item from a python list. Within IDLE:
    >>>s=[1,2,3]
    >>>dir(s)
    >>>help(s.pop)
    >>>t=s.pop(0)
    >>>t
    >>>s
    
    To learn more about IDLE, visit One Day of IDLE Toying.

  • Take a look at this big list of python tutorials. Click on "Beginners".

  • Here is a place for "newbies" to start learning Python: How to think like a computer scientist, python version.

  • You may want to go to the official Python tutorial.

  • You should also be aware of the other online documentation found at python.org. If you can find your way to the documentation, you will see a very important link labeled "keep this under you pillow": Python Library Reference. In there, you can find an references to very powerful Python modules. Here is just one example: Pickle. Some very powerful features of Python end up being hidden from newbies who read a single introductory book, no matter how well-recommended that book is.

  • Speaking of books, do you want to invest in some books about Python? These two go well together: Practical Python and Python Cookbook. Check out the reviews at amazon.com.

Python advocacy

But why has Python been adopted for this course? Why not something else? If this is a burning issue for you, then you may want to investigate:

Task for Spring 2006

You will need to put the following 3 files in a folder/directory where you intend to use Python (firstpy might be an appropriate name). This task does not need any of the meteorological data on Gentry, and should be doable on almost any computer that has a recent version of Python installed. If you plan to use your Python programs in both Windows and Linux, beware of the extra invisible "carriage return" character in Windows text files.

  • Download makePickle.py. Or, if you must do this on Gentry, then enter on the Gentry command line:
    wget http://gentry.metr.ou.edu/pytut/makePickle.py
    

  • Download playmeso.py. (Slight alterations on 2/4/2006. In fact, previously one of the subtasks was mistakenly completed for you, but now it is gone... if you grabbed the earlier version, lucky you!)

  • Download this mesonet data file from 2005/12/27: latest.mdf.
On Linux (Gentry) for example, do the following in the directory where you place the scripts:
chmod u+x *.py
makePickle.py latest.mdf
playmeso.py latest.mdf.pickle
If you use IDLE on Windows, open makePickle.py under the IDLE menu File,Open. Then use the Run menu in the new window that opened. Enter latest.mdf when prompted. (Similarly, enter latest.mdf.pickle when prompted by playmeso.py).

If the scripts worked okay, then prepare to make modifications of playmeso.py. First, make a copy to a new file. For example, on Linux:

cp playmeso.py mymods.py
Open mymods.py with a text editor or with IDLE. Read the comments on how to complete the sub-tasks.

One of the sub-tasks requires making a file new.pickle. You can test to see if you created new.pickle correctly with the little script: pickinsp.py.

Also, to clarify what the goals are, my completed mymods.py dumps this standard output to the monitor, and makes these files: offenders.dat and missmeas.dat.

Executing

pickinsp.py new.pickle
makes this output.

this is an obsolete site
go to new site
go to obsolete home page

pix
Move to top of page