[albatross-users] displaying two-dimensional arrays of data
Dave Cole
djc at object-craft.com.au
Tue Jun 24 11:23:59 EST 2003
> Michael C. Neel wrote:
> > I prefer to use an al-exec to get friendly names, such as:
> > <al-for expr="mylist" iter="line">
> > <al-exec expr="name, title, company, etc = mylist.value()">
> > <al-value expr="name">
I tend not to use two dimensional arrays if I can avoid them. I just
build single dimensional arrays of attribute only objects. If makes
the code much more readable.
> > If things are more complex I build an array of objects, and pull them
> > out as such:
> > <al-for expr="mylist" iter="line">
> > <al-exec expr="person = mylist.value()">
> > <al-value expr="person.name">
>
> this is great. This is the kind of thing that should be in a helpful
> hints/best practices/cookbook section of the documentation.
>
> question: does the lval names get put into the context.local.<blah>
> namespace or are they in their own namespace? I'm worried about
> overwriting data on trying to bring into the template.
It all happens in the local namespace. In Python assignments to
variables happen in the local namespace unless you declare a name to
be global. Albatross uses this nice feature to provide a local and
global namespace.
The templating system uses ctx.locals.__dict__ as the local namespace
in expressions and the globals of the function that ran the template
as the global namespace.
You can see this happening in the following:
>>> import albatross
>>> def templ(ctx, text):
... albatross.Template(ctx, '<magic>', text).to_html(ctx)
...
>>> ctx = albatross.SimpleContext('.')
>>> templ(ctx, '<al-exec expr="a = 3">')
>>> ctx.locals.a
3
>>> templ(ctx, '<al-exec expr="global a; a = 4">')
>>> a
4
- Dave
--
http://www.object-craft.com.au
More information about the Albatross-users
mailing list