Question about name scope

Olive diolu at
Wed Feb 1 18:11:17 CET 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 *


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.


More information about the Python-list mailing list