Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

PyMeld

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.

View blog reactions

Next: CSS2 is five years old

Previous: Ninety percent of everything is crap

2 comments

  1. PyMeld is attractive, but not very practical as you have to drive every templating element from your code. Contrast this with ZPT where the display logic is in the template, and in your code you only have to create the appropriate context. http://www.asiatica.org/~ludo/archive/2003/06/Pyth on_pymeld.html

    ludo - 1st November 2003 09:11 - #

  2. Since PyMeld handles XML in addition to simple HTML, it is particularly useful for repetitive real-time SVG graphic display updates; i.e., server-push data. Last time I looked (Zope 3), ZPT was only applicable to HTML (and transitional XHTML). Also, there is nothing to stop one from doing PyMeld processing of documents that use other templating mechanisms as well (say ZPT, Nevow, CherryPy/Cheetah, etc.) in order to combine server-push with subsequent client-pull mechanisms.

    Norm Petterson - 25th February 2005 21:08 - #

Comments are closed.

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

A django site