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 8393177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:42:54+00:00 2026-06-09T19:42:54+00:00

I thought about this for a while and can’t think of a better title,

  • 0

I thought about this for a while and can’t think of a better title, sorry.

I’m new’ish to Python, and (like many other’s it seems) I just can’t get my head around import.

I think I understand ‘modules’ and ‘packages’, classes and attributes and all that. It’s one specific behavior I need clarified.

Say I have a file, foo.py. It has one line it:

x = 1

If, in another file, I `import foo”, I can reference x. And, wonderfully, in another file I can import foo and now those two files can share x. Leaving classes out of the discussion for simplicity, I believe this is the pythonic way to share attributes between files.

Here’s the question: Is is fair to say, when I import foo, that foo.py itself is, (for lack of a better metaphor), secretly instantiated by the interpreter?

I realize if I define a class in a module, it follow traditional rules and only become instantiated if I explicitly do so. But, the python interpreter (via the import statement) instantiating an instance of my module in the global namespace is the only way to explain the attribute sharing behavior.

Is this true? Semi-true? Or am I wandering with the Sleestaks in the Land of the Lost?

  • 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-09T19:42:55+00:00Added an answer on June 9, 2026 at 7:42 pm

    The import creates an instance of a “module” object. It is worth knowing that this is created only the first time the module is imported. The following times it is imported you are getting a reference to the original. You can create your own module objects on the fly with a bit of instrospection.

    import glob  # Import any python module
    moduleType = type(glob)
    
    onTheFly = moduleType("OnTheFly", "Docstring for this module")
    

    Although there isn’t much benefit to creating these.

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

Sidebar

Related Questions

We have a project that’s using many C++11 facilities, and we thought about this
I have this object below: I thought about putting the messages in html like
I've published my website many times. But didn't think about this though until I
I have wondered/worried about this for a while now, so I thought I'd ask
How can one loop through a generator? I thought about this way: gen =
I've been curious about this for a while so I thought I would ask
I thought I'd find more about this topic but I didn't. I have to
I know this might sound easy. I thought about using the first dot(.) which
This question is about a data structure I thought of. It is a dynamic
This is a thought problem, and one I have been wrestling with for about

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.