Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:22:11+00:00 2026-06-08T12:22:11+00:00

I’m trying to understand the difference between a loaded module vs. an imported module,

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:22:12+00:00Added an answer on June 8, 2026 at 12:22 pm

    The difference between a module being imported and being loaded is what is placed into your current module’s namespace. A module will only get loaded once (in ordinary situations), but can be imported many times, from many different places. A loaded module may not be accessible in a given namespace, if it hasn’t been imported there. For instance, you can load a module without importing it under its name using the from module import name syntax (you’ll be able to access the specified name, but not the module itself).

    You’re seeing the os module in the sys.modules dictionary because it’s used internally by the python interpreter, and so it is always loaded at startup. You can’t access it using the name “os” though, because it isn’t automatically imported into your namespace.

    However, you can bypass the normal import mechanisms in a few ways. For instance, try this:

    import sys
    os = sys.modules["os"]
    

    You’ll now be able to access the os module just as if you had done import os.

    That’s because that code is exactly what an import statement does when you request a module that has already been loaded. However, if you try the code above with a module that isn’t loaded yet, it won’t work (you’ll get a key error from the sys.modules dictionary). The import statement loads new modules in addition to adding them to the current namespace. While you can manually load modules and further work around the regular import system, there’s rarely a good reason to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.