Why does __builtins__ mean different things...

J

James Stroud

Hello all,

Say I have the following module

# amodule.py
print __builtins__
# end of module

Then I have the following little helper script:

# helper.py
import amodule
# end of helper script

Now, I do this at the command line:

python amodule.py

And I get the following output:

<module '__builtin__' (built-in)>

Which is good.

Now, I do this:

python helper.py

and I get the following output:

{'IndexError': <type 'exceptions.IndexError'>, 'all;:
.... [etc]

I.e.: __builtins__ is a dict when referenced in an imported module, but
in *the exact same code*, when executed as a script, it becomes a
module! Is this a bug?

In other words, what is the good of this? For the purposes of argument,
the bad of this is the behavior above. I'm guessing its a bug.

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top