Simon Willison’s Weblog

Subscribe

PyMeld

15th May 2003

PyMeld is a concrete implementation of something I’ve been thinking about for months: A template system that takes an XHTML page as a template and manipulates it based on cloning and modifying elements within the template identified using their ID attribute. It’s a very elegant solution that makes good use of Python’s object overloading support to make manipulating templates as intuitive as possible. Maybe the same thing will be possible in PHP once the new overloading functions become part of the standard package.

If you decide to have a play with PyMeld you may run in to the limitation that, because class is a reserved word in Python, you can’t set the class of an element using the standard page.someElementID.class = "something" syntax. You can however achieve the same thing using Python’s setattr built in function: setattr(page.someElementID, 'class', 'something'). That tip comes courtesy of the module’s author who sorted it out for me within about 10 minutes of my email query.

This is PyMeld by Simon Willison, posted on 15th May 2003.

Next: CSS2 is five years old

Previous: Ninety percent of everything is crap

Previously hosted at http://simon.incutio.com/archive/2003/05/15/pyMeld