[Python-ideas] Literate python?

Ryan Freckleton ryan.freckleton at gmail.com
Tue Mar 8 23:07:58 CET 2011


I absolutely love the idea of literate programming and have investigated
several existing projects that attempt this.

There already exist several third-party packages for literate programming in
python:
 - PyLit (http://pylit.berlios.de/)
 - PyWeb (http://pywebtool.sourceforge.net/)
 - Leo (http://webpages.charter.net/edreamleo/front.html)

PyLit approaches it by transforming between RestructuredText and source,
which allows line numbers to match for debugging. PyWeb takes the more
traditional noweb/tangle approach of creating source from a document.

The biggest issue is making exceptions and debugging nice if you allow code
re-ordering. Interpreter support may help with this, but I think there's
still a lot to be explored by third party libraries (importlib, ast
transforms, etc.)

I'm not sure if python-ideas is the appropriate venue, but if you'd like to
develop this idea more, please feel free to email me.

Cheers
=====
--Ryan E. Freckleton


On Tue, Mar 8, 2011 at 3:02 PM, Mike Meyer <mwm at mired.org> wrote:

> Wild idea, swiped directly from haskell/ghc:
>
> How about making the python interpreter just a little bit smarter, to
> support literate programming? Add a 'literate python' mode, triggered
> by file type being .pyl, a '-l' option, or the interpreter being run
> as 'lpython', then the compiler does a little bit of filtering before
> compiling (and potentially saving .pyc/.pyo) the file.
>
> If the first non-white-space character after the shebang line (if
> present) is a backslash, then the compiler ignores lines until it sees
> a line consisting of \begin{code} (which could be the first line),
> then compiles lines until it sees a line consisting of \end{code},
> after which it switches back to searching for \begin{code}.
>
> Otherwise, all lines (again, after the shebang line, if present) are
> treated as comments until the compiler sees a line starting with "> "
> (that's greater than followed by space) following an empty line, which
> causes the compiler to start stripping the "> " from lines and
> compiles them until it finds a line that doesn't start with "> ".
>
>       <mike
> --
> Mike Meyer <mwm at mired.org>
> http://www.mired.org/consulting.html
> Independent Software developer/SCM consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110308/c47ccad5/attachment.html>


More information about the Python-ideas mailing list