Python and Literate Programming

Philip H. Jensen pjensen at columbus.rr.com
Thu Nov 4 07:32:50 CET 1999


Greetings.  I'm a recent convert to Python, and wish I had looked into
it years ago.  As I said in a posting on my local Linux UG's mailing
list, "I like everything about Python, whereas there are many things
about Perl that I don't like."

Incidentally, I'm also a booster for Modula-3, and of course Python
has well-known and intentional similarities to M3.  But one of my other
enthusiasms is Literate Programming, and I'm wondering about the
possibilities for it in Python.

Documentation texts can be easily accomodated, as can pretty-printing.
But for me, the core of LP, which I use (e.g. in CWEB) even if I never
run the program through CWEAVE, is >> factoring <<.

Here's how it might look in a Python-friendly form.

	if not dictionary.has_key(word):
	    <Inform the user that |word| is not present in
		the dictionary, and take action as directed>

then elsewhere in the program:

	<Inform the user that |word| is not present...>:
	    code...

***
Now, personally I would like to see this in the language itself,
but that seems unlikely.  What would be essential, though would be

  1) a hook whereby "import foo" would see if there was a "foo.pyw"
     more recent than "foo.py", and if so, would invoke a pytangle
     program, and
  2) a means for file and line information to be passed along, so
     that error messages would refer to the .pyw source.

Any interest?  If I myself were to work on patches along these
lines, could they become candidates for inclusion in the mainstream
source tree?

    (I have some other Python development ideas,
     but will save them for later postings.)
  Phil Jensen
  pjensen at columbus.rr.com 





More information about the Python-list mailing list