Useful resources for python programming and debugging, data sources, and project management.

Python Startup

  • Python2 or Python3?
    • Short Answer: Python2.7 is often still used for research because many Python modules are written in Python version 2. Python 3 is quickly becoming the standard version, and many packages now offer python3 distributions.
    • Here's a great tutorial with examples explaining the differences between Python 2 and Python 3.
    • Anna writes code in Python2.7, but plans to make support code compatible with Python 3. Email Anna if you find an issue.
    • Python2 and python3 are both available on the Macs in the ETC labs. Type python or python3 and double check the version. Type quit() to exit the interpreter.
  • Instructions for installing Python on your personal machine.
    • If you are using a Mac, python is probably already installed. You can update it to the latest version using this tutorial.
    • If you are using a PC, Python is probably not yet installed. On the Python for Windows page, download the appropriate windows installation.

Forgot some syntax? Have a bug?

  • If the bug is from the support code and you are using Python3, there may be an improperly-formatted print statement. Notify Anna.
  • Make sure your Python Path is set correctly. See instructions below
  • Double check your syntax with the Python Cheat Sheet.
  • The online Python Tutor visualizes Python code and shows the memory tables (called "data frames") in an interactive, step-by-step fashion.
  • This PDF slide deck from Bio131 covers most of the typical python concepts we will use.
  • New! Useful Tabs to Spaces converter.

Useful Pieces of the Python Standard Library [python2] [python3]

Setting your Python Path

How does Python know where random.py is? What about one of the files your provide, such as graphspace_utils.py? When importing a module,
  1. Python first looks in the current directory. If graphspace_utils.py is there, so it can be imported.
  2. If the module (e.g., random.py) is not in the current directory, then it will look in a list of previously-determined directory locations.
  3. If the module is not in the list of locations, then Python will throw an error.
This list of previously-determined directory locations is specified in your $PYTHONPATH environment variable. If you have a directory that contains frequently-used modules (e.g., the directory containing the *_utils.py scripts), you can add this directory to the $PYTHONPATH variable. Instructions depend on your machine.