Question

I have defined a dictionary in python:

tal:define="dic python:{'a':'1', 'b':'2'};"

I have another variable defined using tal:define called var, which is either 'a' or 'b'. I get an error when I try to do:

tal:define="foo python:dic['${var}'];"

(foo would then be '1' or '2') I get KeyError: '${var}'. I've tried dic[$var], dic[var], etc and they all don't work. How do I use a variable defined previously using tal:define as a key to a dictionary to get its value.

Was it helpful?

Solution 2

DonCallisto's dic[var] does work

OTHER TIPS

Path expression syntax:

tal:define="foo dic/?var"

Python expression syntax:

tal:define="foo python:dic[var]"

See Zope Book for description of ?var syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top