Personal tools
You are here: Home Weblog Archive 2006 November

Entries For: November 2006

2006-11-23

Setting a dynamic i18n:domain in a ZPT template

Filed Under:

<h2 tal:define="statusMessage python:request.get('statusMessage');
                   domain python:request.get('domain')"
       tal:attributes="i18n:domain domain;
                       i18n:translate string:">someText</h2>

2006-11-07

Getting the parent object in an acquisition context

Filed Under:

To get the parent of an object, you'd have to use this code:

myparent = aq_inner.aq_parent.aq_self

2006-11-06

One liner to get the common elements of several lists

Filed Under:

While doing an exercise with a mockup catalog and indexes, I ran into the problem of filtering several lists and returning the common elements from the list. The following example demonstrate the usage of reduce(), one of the functional programming constructs that are less common and obvious in their usage.

>>> a = [1,2,3,4]
>>> b = [2,3,4,5]
>>> c = [1,2,4,6]
>>> d = [0,2,3]
>>> z = [a,b,c,d]
>>> z = reduce(lambda i,j:list(set(i).intersection(j)), z)
>>> z
[2]
Weblog
Atom
RDF
RSS 2.0
Powered by Quills
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: