whassup? builtins? python3000? Naah can't be right?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Feb 1 17:27:46 EST 2010


En Sun, 31 Jan 2010 18:17:04 -0300, _wolf <wolfgang.lipp at gmail.com>  
escribió:

> dear pythoneers,
>
> i would be very gladly accept any commentaries about what this
> sentence, gleaned from  
> http://celabs.com/python-3.1/reference/executionmodel.html,
> is meant to mean, or why gods have decided this is the way to go. i
> anticipate this guy named Kay Schluehr will have a say on that, or
> maybe even the BDFL will care to pronounce ``__builtins__`` the
> correct way to his fallovers, followers, and fellownerds::
>
>   The built-in namespace associated with the execution of
>   a code block is actually found by looking up the name
>   __builtins__ in its global namespace; this should be a
>   dictionary or a module (in the latter case the module’s
>   dictionary is used). By default, when in the __main__
>   module, __builtins__ is the built-in module builtins;
>   when in any other module, __builtins__ is an alias for
>   the dictionary of the builtins module itself.
>   __builtins__ can be set to a user-created dictionary to
>   create a weak form of restricted execution.

Short answer: use `import builtins` (spelled __builtin__, no 's' and  
double underscores, in Python 2.x) to access the module containing the  
predefined (built-in) objects.

Everything else is an implementation detail.

-- 
Gabriel Genellina




More information about the Python-list mailing list