Python sys.modules contains a module which is not yet imported

Viewed 3403

I'm trying to understand the difference between a loaded module vs. an imported module, if there is any.

I'm working in Python 2.7.3, and am just running Python from the command line.

If I execute:

import sys
sys.modules

I get a list which includes os, for example. The documentation says that sys.modules is a list of "loaded" modules. However, if I try to run something like os.environ, I get a NameError which tells me that os is not defined. However, if I then run import os, this resolves the issue. Can anyone explain why os exists in sys.modules prior to me actually importing the module?

1 Answers
Related