I have a question, which is basically a question on Python template engine capability.
Suppose I have the following code:
import string as st
def foo(bar):
if bar:
t = 'world'
else:
t = 'not happening'
return t
temp = st.Template("hello $bar")
final = temp.some_substitute_magic()
and then
print final
should give
hello world
Is it possible to do that with some Python magic?
I know how to do a safe_substitute with a dictionary, but I would like to know how to do a substitute with a function to which every identifier (in this case $bar) is passed and then the returned value is substituted into the template.
Quite easy actually 🙂
Just emulate the workings of a dict and you’re done.