[Python-ideas] Literate python?

Mike Meyer mwm at mired.org
Tue Mar 8 23:02:10 CET 2011

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 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

More information about the Python-ideas mailing list