Table of Contents

Python tools for software carpentry

Lecturer: Pietro Berkes, <berkes _AT_ brandeis _DOT_ edu>

Download the cheat sheets for all the tools and methods discussed in the lecture!

Course material

Slides: Download slides

Exercises:

Outline of the lecture (2h):

  1. Unit testing
    • unittest
    • testing with numpy arrays
    • what to test and how for scientific programming
    • code coverage (coverage.py)
  2. Debugging
    • pdb
  3. Profiling
    • timeit
    • cProfile
  4. Other useful tools
    • documenting: pydoc, doctest
    • static checking: pylint

Many live demos, music and dances!

Good programming practices

Software carpentry in general

Two comprehensive software carpentry courses:

University of Alberta

Tiziano's course at the Bernstein center in Berlin

The classic book about software carpentry: The pragmatic programmer

Coding standards

PEP8, the official Python style guide

pylint , tool to check coding standards

Test suites

unittest, the standard Python test framework

py.test, an alternative framework that simplifies writing tests and allows for extension and customization of test experience

nose, another popular alternative

doctest, write tests inside of docstrings

Debugging

pdb, the standard python debugger

winpdb, a graphical interface for pdb. It's platform-independent despite its name.

DDD (DataDisplayDebugger), graphical general-purpose debugger.

Python IDEs often have a built-in debugger.

Profiling

cProfile, the batteries included Python profiler

timeit, built-in Python module to measure the execution time of small code parts

RunSnakeRun, a wxPython-based visualization of profiling results – very intuitive!