[Pythonmac-SIG] __builtins__ a dictionary or a module?
Jonathan Wight
JWight@bigfoot.com
Thu, 05 Apr 2001 01:38:31 -0500
On 04/03/2001 23:51, "Jonathan Wight" <JWight@bigfoot.com> wrote:
> There is a weirdness though and I haven't figured it out. If I run this code
> in the Terminal Python:
>
> print dir(__builtins__)
>
> I get something a lot like this. About 40 entries in the list.
>
> ['ArithmeticError', 'AssertionError', <--snipped--> 'vars', 'xrange', 'zip']
>
> If I do the same inside ToxicEdit I get this:
>
> ['clear', 'copy', 'get', 'has_key', 'items', 'keys', 'popitem',
> 'setdefault', 'update', 'values']
>
> Which looks like the methods of a dictionary item. The odd thing is is that
> seems to be correct (at least superficially). Because if I don't install the
> __builtins__ module commands like dir() wouldn't even work. Weird.
To follow this up...
It turns out if I run ToxicEdit and do a 'print type(__builtins__)' I get
the response of "<type 'dictionary'>". But from the BSD (and MacPython's)
console the same query returns <type 'module'>.
If I run Just's Python IDE and run the same code it tells mes that
__builtins__ is a module.
And finally if I run the following code from within the Interactive console
contained in standard 'code.py' file I get told __builtins__ is a
dictionary.
So what is it? Is __builtins__ a module or a dictionary? I know that they're
essentially the same thing, but it unnerves me to have the same code produce
different results in different platforms.
Anyone know what is going on? (Should I send this query to the main python
list?)
Jon