Entries For: November 2006
2006-11-23
Setting a dynamic i18n:domain in a ZPT template
<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
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
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]