What is an alternative to eval in this situation?
- by CppLearner
Many of my view functions do similar things. For the most part, they reverse to a different views upon clicking a button / a text link.
So I wrote a helper function render_reverse
def render_reverse(f, args): # args are all string type
return eval('reverse(' + f + ', ' + args + ')' )
eval is a bad practice, and is pretty slow. It takes 3 seconds to start redirecting, whereas calling reverse directly takes less than 1 second to start redirecting.
What alternative do I have? By the way, the function above doesn't work properly. I was modelling after this line (which works)
eval('reverse("homepage", args=["abcdefg"])')
Thanks.