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

  • Home
  • SEARCH
  • 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 6951653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:14:49+00:00 2026-05-27T14:14:49+00:00

I am wondering why the directory (subpackage) that holds submodules in a python package

  • 0

I am wondering why the directory (subpackage) that holds submodules in a python package shows up as a symbol when the package is imported. For instance, if I have this package:

PyModTest/                        Top-level package
          __init__.py             Initialize the package
          Source/                 Subpackage holding source files
                 __init__.py
                 WildMod.py        Submodule containing a function: 'WildFunc'

where the top level __init__.py looks like this:

#!/usr/bin/env python

from Source.WildMod import WildFunc

and, for completeness’ sake, the lower level __init__.py looks like this:

#!/usr/bin/env python

__all__ = ["WildMod"]

OK, so now I open up the interpreter, import the module, and look at the symbols:

>>> import PyModTest
>>> dir(PyModTest)
['Source', 'WildFunc', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

SEE, the ‘Source’ module shows up, even though I never specifically imported it!

The only symbol (besides the private ones) that I want to see is my ‘WildFunc’. Is there any way to hide the ‘Source’ package?

  • 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-05-27T14:14:50+00:00Added an answer on May 27, 2026 at 2:14 pm

    Two things to note here:

    • In Python, modules are actual objects, and the dot that appears between their names represents an actual attribute access
    • You are doing a relative import, meaning that Source is actually PyModTest.Source (thanks to TokenMacGuy for pointing this out)

    So: in order to import PyModTest.Source.WildMod.WildFunc, Python has to

    1. import PyModTest (which was already done by you)
    2. check and see if it has an attribute called Source, and if not, create the attribute by importing it from PyModTest/Source/__init__.py
    3. check and see if that has an attribute called WildMod, and if not, create the attribute by importing it from PyModTest/Source/WildMod.py
    4. check and see if that has an attribute called WildFunc (which it does)

    Some relevant details are discussed in PEP 302 and in the Python language reference.

    Deeper down in the mechanism, a dotted name import is split up by
    its components. For “import spam.ham“, first an “import spam” is
    done, and only when that succeeds is “ham” imported as a submodule
    of “spam“.

    If you don’t want to have a variable named Source, that’s easy to fix: just del Source after you import the function. But bear in mind that it will prevent any code that runs later on from accessing PyModTest.Source.<anything> (except for WildFunc, since you have saved a reference to that). I would definitely suggest just ignoring the reference to Source, not deleting it, since it’s not hurting anything.

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

Sidebar

Related Questions

We currently have a View that queries active directory info. I was wondering if
Wondering if this is possible. We have an 3rd Party library that contains identification
Just wondering... I have some code (disabling certain logging output) that I'd like to
I was just wondering if this is possible using TortoiseSVN: I have a file
Suppose you have a directory structure like this: A/ B/ a.1 b.2 c.3 I'm
I just wondering about this.It is said that .NET is better than MFC in
I've been wondering why python gets installed in directory named Frameworks? (though it's not
I 'm wondering of any mechanism that one could use to change the directory
I know this isn't directly related to programming, but I was wondering if anyone
Wondering how to open many new windows with Javascript. I have found plenty of

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.