Question about name scope

Rick Johnson rantingrickjohnson at gmail.com
Wed Feb 1 18:21:22 CET 2012


On Feb 1, 11:11 am, Olive <di... at bigfoot.com> wrote:

> 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.

Seeing is believing!

>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']
>>> from math import *
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'acos',
'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil',
'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp',
'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum',
'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10',
'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan',
'tanh', 'trunc']
>>> ================================ RESTART ================================
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']
>>> from math import sin, cos
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'cos', 'sin']
>>>



More information about the Python-list mailing list