3 ms·
It can be somewhat handy when working in interactive mode, though it has a very informal feel to it. One (bad) example would go along the lines of: >>> def f(
by Panoramix 16y ago
It can be somewhat handy when working in interactive mode, though it has a very informal feel to it.
One (bad) example would go along the lines of:
>>> def f(x):
... if x in dir(scipy):
... print eval("scipy." + x + "(2)")
...
>>> f("sin")
0.909297426826
Then you can let the user plot whatever function they want.
- IgorPartola 16y agoCan't you use scipy.__dict__ to look up the function name in this case? scipy.__dict__[x](2)
- bobbyi 16y agoIt would be preferable to use getattr(scipy, x) rather than reaching inside the internals of the object (module).
- kingkilr 16y agogetattr(scipy, x)(2)