Question about name scope
Olive
diolu at bigfoot.com
Wed Feb 1 12:11:17 EST 2012
I am learning python and maybe this is obvious but I have not been able
to see a solution. What I would like to do is to be able to execute a
function within the namespace I would have obtained with from <module>
import *
For example if I write:
def f(a):
return sin(a)+cos(a)
I could then do:
from math import *
f(5)
But I have polluted my global namespace with all what's defined in
math. I would like to be able to do something like "from math import *"
at the f level alone.
The main reason for this is the sympy module for CAS (computer algebra).
It reimplement a lot of functions and define all the letters as symbolic
variables. Writing sympy.<function> everywhere is inconvenient.
Importing all the symbols in the global namespace would lead to name
clash. It would be nice if I could import all the sympy names but for a
given function only.
Olive
More information about the Python-list
mailing list