Cow header

Pweave - Sweave for Python

Author: Matti Pastell
Tags: Python, Pweave, Sweave
Mar 03 2010

After looking into different options for literate programming with Python I ended up writing my own tool and call it Pweave. I have tried to implement the functionality of Sweave, that I really like and use for my R projects. Pweave is a single python script that is able to weave a python code between <<>>= and @ blocks and include the results in the document. It can be used with reStructured text and Latex documents.

Update:. I’ve set up a Pweave website, you can also download it here.

Codeblock options Pweave currently allows following options for the codeblocks (e.g. <>=): fig True or False. Whether a matplotlib plot produced in the codeblock should be included in the file. echo True or False. Echo the python code in the codeblock? eval True or False. Should the codeblock be evaluated? results “rst”, “tex” or “verbatim”. The output format of the printed results. Example: The syntax of Pweave is similar to Sweave, here is a small example sourcefile ma.Pnw which can be processed with Pweave using:

Pweave ma.Pnw

which produces a reStructured text document ma.rst, which can in turn be processed to ma.pdf with rst2latex and pdflatex.

comments powered by Disqus