pythonplonezopetemplate-talzpt

How to retrieve the value of a key in a dictionary using a variable defined in TAL?


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.


Solution

  • DonCallisto's dic[var] does work