import vs imp and friends.

Christian Heimes lists at cheimes.de
Thu Jul 23 11:04:05 EDT 2009


Emanuele D'Arrigo wrote:
> Now the question. Apart from checking sys.module first and eventually
> adding the new module to it if it isn't there already, and apart from
> setting __file__, is there anything else that import does and this
> snippet doesn't?

The import statement does several things. For instance it holds the
import lock to stop other threads from importing the same module again.
It also does lots of additional work for packages like relative imports,
checking __path__, setting attributes on parent packages and so on. The
import system also does a lot of work in order to find and load a
module, too.

Christian






More information about the Python-list mailing list