This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: type of __builtins__ changes if in main module or not
Type: behavior Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: loewis, nnorwitz
Priority: normal Keywords:

Created on 2008-12-07 20:48 by nnorwitz, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg77252 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2008-12-07 20:48
This happens on 2.4 and 3.0, probably all versions:

When running this simple program (save to a file):

print(type(__builtins__))
__import__(__file__.split('/')[-1][:-3])

I get:
<type 'module'>
<type 'dict'>


I would expect the type to be consistent regardless of whether executing
the main module or from the imported module.  I haven't looked into why
this is happening or if it makes sense.  It was unexpected.
msg77254 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-12-07 20:57
This is documented, intentional behavior:

http://docs.python.org/library/__builtin__.html?highlight=__builtins__
History
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48832
2008-12-07 20:57:07loewissetstatus: open -> closed
resolution: wont fix
messages: + msg77254
nosy: + loewis
2008-12-07 20:48:38nnorwitzcreate