markup.py - HTML/XML generator

Fredrik Lundh fredrik at pythonware.com
Wed Mar 22 03:27:47 EST 2006


Gerard Flanagan wrote:

> Now I can do this:
>
>     page = HtmlPage('Test Page')
>     navbar = page.div(id='left').ul(css='navbar')
>     for href,link in {'/home':'Home', '/shop':'Shop',
> '/cart':'Cart'}.iteritems():
>         navbar.li.a(link,href=href)
>     page.div(id='main').h1('Header').p('<Text Goes Here>')
>
> So *that's* what '__call__' does - I am enlightened!

just wait until you figure out what iteritems do ;-)

:::

I'm sure you already know it, but dictionaries aren't ordered, so that
navigation bar may not come out as you'd expect.

>>> {"/home": "Home", "/shop": "Shop", "/cart": "Cart"}
{'/cart': 'Cart', '/shop': 'Shop', '/home': 'Home'}

</F>






More information about the Python-list mailing list