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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:22:00+00:00 2026-05-10T19:22:00+00:00

When using __import__ with a dotted name, something like: somepackage.somemodule , the module returned

  • 0

When using __import__ with a dotted name, something like: somepackage.somemodule, the module returned isn’t somemodule, whatever is returned seems to be mostly empty! what’s going on here?

  • 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. 2026-05-10T19:22:00+00:00Added an answer on May 10, 2026 at 7:22 pm

    From the python docs on __import__:

    __import__( name[, globals[, locals[, fromlist[, level]]]]) 

    …

    When the name variable is of the form package.module, normally, the top-level package (the name up till the first dot) is returned, not the module named by name. However, when a non-empty fromlist argument is given, the module named by name is returned. This is done for compatibility with the bytecode generated for the different kinds of import statement; when using ‘import spam.ham.eggs’, the top-level package spam must be placed in the importing namespace, but when using ‘from spam.ham import eggs’, the spam.ham subpackage must be used to find the eggs variable. As a workaround for this behavior, use getattr() to extract the desired components. For example, you could define the following helper:

    def my_import(name):     mod = __import__(name)     components = name.split('.')     for comp in components[1:]:         mod = getattr(mod, comp)     return mod 

    To paraphrase:

    When you ask for somepackage.somemodule, __import__ returns somepackage.__init__.py, which is often empty.

    It will return somemodule if you provide fromlist (a list of the variable names inside somemodule you want, which are not actually returned)

    You can also, as I did, use the function they suggest.

    Note: I asked this question fully intending to answer it myself. There was a big bug in my code, and having misdiagnosed it, it took me a long time to figure it out, so I figured I’d help the SO community out and post the gotcha I ran into here.

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

Sidebar

Ask A Question

Stats

  • Questions 103k
  • Answers 103k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer UTF-8 is a better option as it really support all… May 11, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer I tended to find the Open XML SDK much better… May 11, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer Mutex is the way to go. It's a lot less… May 11, 2026 at 8:20 pm

Related Questions

Update: This turned into a blog post, with updated links and code, over at
I want to write a function that works on any Scala type with a
Using VC2005, I have 3 projects to build: libA (contains a typelib, results in
Scenario: over 1.5GB of text and csv files that I need to process mathematically.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.