import & __import__

Chris Armstrong punck at
Sun Mar 12 23:28:32 CET 2000

Hi all. I'm pretty much a newbie to Python, and I have a question about 
import vs __import__. I'm implementing dynamically imported modules in
a game I'm writing, and I need to use __import__ to do this. One thing I
noticed is that __import__ doesn't seem to execute the modules that it
imports, while import does.. The docs for __import__ don't mention anything
about this, and I'm just curious about it. I tested this by making a simple
module that just has `` print "Hi." '' in it. `` import modulename '' caused
it to print out "Hi." while `` foobar = __import__("modulename") '' didn't.
This isn't really important to me, I was just curious about it.

Chris Armstrong

Geek code version 3.12
GCS d? s:-- a--- C+++ UL++++>++++ P++ L+++ E--- W++ N+ o? K- w-- 
O-- !M V PS+(+++) PE? Y+(--) PGP(--) t+ 5 X+ R tv+ b+>++ DI+ D+++ 
G e- h!(--) r- y?
Go to to find out what on earth this is.

More information about the Python-list mailing list