Personal tools
You are here: Home development ScopeInPython


  • the global scope of a function defined in a module is that module's namespace, no matter from where or by what alias the function is called

  • The global namespace for a module is created when the module definition is read in

  • statements executed by the top-level invocation of the interpreter, either read from a script file or interactively, are considered part of a module called __main__, so they have their own global namespace

Scope Ordering

  1. the innermost scope consists of the local names and is searched first

  2. the namespaces of any enclosing functions are then searched starting with the nearest enclosing scope

  3. the middle scope, searched next, contains the current module's global names

  4. the outermost scope (searched last) is the namespace containing built-in names

Loading Modules

  1. current directory


  3. installation-dependent default


  • some functions are part of the global namespace and cannot be removed

  • math functions like abs()

  • technically, they are part of a module called __builtin__


Powered by IEM Powered by Plone Section 508 WCAG Valid XHTML Valid CSS Usable in any browser