Invoking Python from Python

Mike Meyer mwm at mired.org
Tue Nov 8 20:14:38 EST 2005


claird at lairds.us (Cameron Laird) writes:
> In article <pan.2005.11.08.16.21.11.472836 at thomas-guettler.de>,
> Thomas Guettler  <niemand.leermann at thomas-guettler.de> wrote:
>>creating source code with a script, is no good solution. 
>>Once I had to maintain lisp code which stored its data in lisp code, too
>>(incl. conditions and loops). It was a nightmare.
> Yes and no.  There are times when it's justified.  I ENTIRELY
> agree, though, that many people who *think* that's what they
> want to do simply don't understand how dynamic base Python is,
> and therefore don't realize how much easier it can be to write
> a single, unified application.

Yup. Python can do a lot of things directly that other languages might
solve with code that writes code. However, that's a *very* powerful
technic, and not everything it does can be done with lesser tools. On
the other hand, it's a *very* powerful technic, and abusing it can
easilyi create unmaintainable code.

> At this point, 'twould be appropriate to describe an instance
> or two in which code generation is a good idea.  While I have
> some, they're tedious to make clear.  Maybe I'll do so in a
> follow-up ...

Since Cameron didn't provide examples, let me grab a simple one. The
cheetah templating system works by creating Python programs from the
template. The programs, when run, output the "filled in" template. The
templates are generally more maintainable than the raw python - even
if you cleaned up all the things Cheetah does to make writing
templates easier. This model makes it possible for Cheetah templates
use inheritance - they can inherit from each other, from python
classes, and python classes can inherit from them.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list