Pythonic way of web-programming

Bob Ippolito bob at redivi.com
Tue Apr 22 17:50:46 EDT 2003


David Abrahams <dave at boost-consulting.com> wrote in message news:<848yu3o5o6.fsf at boost-consulting.com>...
> Mark E. <snowball3 at bigfoot.com> writes:
> 
> > David Abrahams <dave at boost-consulting.com> wrote:
> >
> >>    xml.sometag(attr1="value1", attr2="value2", ...)[ "contents" ]
> >
> > Of course there are always corner cases to deal with. For example, what's a good way
> > to handle XHTML's 'class' attribute?
> >
> > xml.sometag(class="css_class_name")["contents"]
> > won't work.
> >
> > One could map 'foo_' to 'foo' to handle conflicting names used in xml/html, or allow
> > a dictionary to serve the same purpose:
> >
> > xml.sometag({"attr1" : "value1", "class" : "value2"})["contents"]
> 
> Sure, you have lots of options. Also:
> 
>     xml.sometag(class_("value2"), attr1 = "value1")["contents"]
> 
>     xml.sometag({'class':"value2", 'while':"value3"}, attr1 = "value1")["contents"]
> 
>     xml.sometag(attr1 = "value1", _ = {'class':"value2", 'while':"value3"})["contents"]
> 
> it's all in the fun of designing domain-specific sublanguages.

well, in our implementation (off the top of my head) these are valid:

xml.sometag(_class = 'value2', attr1='value1')['contents']
xml.sometag({'class':'value2'}, attr1='value1')['contents']
xml.sometag('class="value2"', attr1='value1')['contents']
xml.sometag(('class', 'value2'),), attr1='value1')['contents']

The preferred is the first, it's easiest.  It's assumed that you will
never want an attribute that actually starts with an underscore.  If
you do (probably never), you'll have to use one of the other three
options.

-bob




More information about the Python-list mailing list