I absolutely love the idea of literate programming and have investigated several existing projects that attempt this.<br><br>There already exist several third-party packages for literate programming in python:<br> - PyLit (<a href="http://pylit.berlios.de/">http://pylit.berlios.de/</a>)<br>
- PyWeb (<a href="http://pywebtool.sourceforge.net/">http://pywebtool.sourceforge.net/</a>)<br> - Leo (<a href="http://webpages.charter.net/edreamleo/front.html">http://webpages.charter.net/edreamleo/front.html</a>)<br><br>
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.<br><br>
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.)<br>
<br>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.<br><br>Cheers<br clear="all">=====<br>--Ryan E. Freckleton<br>
<br><br><div class="gmail_quote">On Tue, Mar 8, 2011 at 3:02 PM, Mike Meyer <span dir="ltr"><<a href="mailto:mwm@mired.org">mwm@mired.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Wild idea, swiped directly from haskell/ghc:<br>
<br>
How about making the python interpreter just a little bit smarter, to<br>
support literate programming? Add a 'literate python' mode, triggered<br>
by file type being .pyl, a '-l' option, or the interpreter being run<br>
as 'lpython', then the compiler does a little bit of filtering before<br>
compiling (and potentially saving .pyc/.pyo) the file.<br>
<br>
If the first non-white-space character after the shebang line (if<br>
present) is a backslash, then the compiler ignores lines until it sees<br>
a line consisting of \begin{code} (which could be the first line),<br>
then compiles lines until it sees a line consisting of \end{code},<br>
after which it switches back to searching for \begin{code}.<br>
<br>
Otherwise, all lines (again, after the shebang line, if present) are<br>
treated as comments until the compiler sees a line starting with "> "<br>
(that's greater than followed by space) following an empty line, which<br>
causes the compiler to start stripping the "> " from lines and<br>
compiles them until it finds a line that doesn't start with "> ".<br>
<br>
<mike<br>
--<br>
Mike Meyer <<a href="mailto:mwm@mired.org">mwm@mired.org</a>> <a href="http://www.mired.org/consulting.html" target="_blank">http://www.mired.org/consulting.html</a><br>
Independent Software developer/SCM consultant, email for more information.<br>
<br>
O< ascii ribbon campaign - stop html mail - <a href="http://www.asciiribbon.org" target="_blank">www.asciiribbon.org</a><br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</blockquote></div><br>