We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I see eval as a hacky solution. eval should only ever be used with caution and there's usually a better solution. It's fragile (you may accidentally create invalid code) and can be dangerous (can offer ways for malicious code to be injected). It's also significantly slower, because the python code created by eval has to be recompiled on every iteration.
You can do this more cleanly and safely a couple of ways. You could use getattr(). But I prefer just using function references. Remember that class methods are just functions with an object as the first parameter - true in any OO language but directly visible and usable from Python.
String Validators
You are viewing a single comment's thread. Return to all comments →
I see eval as a hacky solution. eval should only ever be used with caution and there's usually a better solution. It's fragile (you may accidentally create invalid code) and can be dangerous (can offer ways for malicious code to be injected). It's also significantly slower, because the python code created by eval has to be recompiled on every iteration.
You can do this more cleanly and safely a couple of ways. You could use getattr(). But I prefer just using function references. Remember that class methods are just functions with an object as the first parameter - true in any OO language but directly visible and usable from Python.
or
Eval is something to use for a quick hack but it's not a good habit.