A Python Introduction

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. 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.

Learning Python

Most of the 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.

Before you learn Python, you may want to learn why you are being asked to learn it: Python Advocacy

And before you learn Python syntax and start writing your own programs, you may want to see some examples of what Python can do: JuliaSets

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

Other tutorials are available at this big list of python tutorials Click on "Beginners".

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 small but very important link labeled Python Library Reference. In there, you can find a 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.

If you want to invest in books, I don't really have any strong recommendations for a beginning book. Check out the reviews at http://amazon.com . I own quite a few python books, I find that I consistently reach for Python Essential Reference.

Reading and analyzing mesonet data files

{*} Here is what you will need for the task (if working on Gentry, heed the advice in GettingFiles):

The python programs have been indented with tabs. Be warned that there is considerable debate about indentation with tabs versus spaces.

You should open those files with a text editor of your choice and study them a bit. Your task requires you to make some modifications of mesorep.py. The requirements of the task are defined with the comments of mesorep.py. Your task is complete when your modified mesorep.py is able to produce this

On Linux (Gentry) the python scripts can be run by changing the file permission to executable:

chmod u+x *.py

Then run them with:

CSVtoPickle.py latest.mdf
mesorep.py latest.mdf.pickle

In Windows, use iPython to navigate to the folder (Task1, for example) in which you placed the scripts. Navigation in iPython requires just using the command ls and cd. Tab completion also helps save typing: hitting the tab key to complete a partially typed word.

cd
cd Desktop/
cd Task1
ls

Once you successfully arrive at your folder, type:

run CSVtoPickle.py latest.mdf
run mesorep.py latest.mdf.pickle

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

cp mesorep.py mymods.py

Then complete the task by editing mymods.py .