It’s easy to include source code that’s automatically run when the documentation is created with sphinx, e.g.:
>>> from pylab import *>>> def f(x): >>> f = where(x>0, cos(x), exp(x)) >>> return f>>> x = linspace(-5, 5*pi, 500) >>> plot(x,f(x)) >>> ylim([-1.2, 1.2])
(Source code)