Modules are global singletons. They are stored in the sys.modules
mapping, to prevent having to load every module each time it is used somewhere.
All globals in a module are exposed as attributes on the module object; math.pi
is one such global. You can alter these globals by assigning to them, and because modules are singleton objects, every reference to the module object will see the change.
Remember, Python names are references; the name math
is indeed 'local' to your module, but it is still a reference to the global <module 'math' from '/usr/lib/python2.7/lib-dynload/math.so'>
object.