Timmy
Timmy

Reputation: 12858

Mako calling function from string?

Is there an easy way to call a function given a string name in mako?

Upvotes: 2

Views: 614

Answers (1)

Mike Boers
Mike Boers

Reputation: 6745

You should be able to look it up in the dict returned by globals(). Eg.:

<$ func_name = 'my_function_name' %>
${globals()[func_name](...)}

Although, this does smell rather nasty to me. If you could expand upon your end game perhaps we can figure out something a bit saner.

Upvotes: 5

Related Questions