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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:40:57+00:00 2026-06-17T23:40:57+00:00

Assume you have a package foo with the following __init__.py : from bar import

  • 0

Assume you have a package foo with the following __init__.py:

from bar import *

With bar being any python module installed with pip install bar.

Now what always works when you can import bar:

from bar import submodule #works
import bar.submodule      #works, too

Now I would assume the following things would all work as well:

from foo import submodule     # a) is possible
import foo.submodule          # b) not possible ("no module named submodule")
from foo.bar import submodule # c) also impossible ("no module named submodule")

Why are they not possible? What would I need to do to make them possible, from the point of view of the foo maintainer?

  • 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-17T23:40:59+00:00Added an answer on June 17, 2026 at 11:40 pm

    submodule and bar are members of the foo module object, not submodules of it. Therefore, they behave just like any other member attribute of foo. You can bring them into the module namespace of a third module with the from foo import ... form, but you can’t directly import them relative to foo. I guess you could if you hacked them in to sys.modules under the desired name manually, but you really shouldn’t be doing anything like that…

    To illustrate the issue:

    foo.py

    # x and y are values in the foo namespace, available as member attributes
    # of the foo module object when foo is imported elsewhere
    x = 'x'
    y = 'y'
    

    bar.py

    # the foo module object is added as a member attribute of bar on import
    # with the name foo in the bar namespace
    import foo
    # the same foo object is aliased within the bar namespace with the name
    # fooy
    import foo as fooy
    # foo.x and foo.y are referenced from the bar namespace as x and y,
    # available as member attributes of the bar module object
    from foo import x, y
    # z is a member attribute of the bar module object
    z = 'z'
    

    baz.py

    # brings a reference to the x, y, and z attributes of bar (x and y
    # come in turn from foo, though that's not relevant to the import;
    # it just cares that bar has x, y, and z attributes), in to the
    # namespace of baz
    from bar import x, y, z
    # won't work, because foo is a member of bar, not a submodule
    import bar.foo
    # will work, for the same reason that importing x, y, and z work
    from bar import foo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume we have following models: from django.db import models class Foo(models.Model): name =
Assume you have a module (eg Foo.pm ) with package Foo . Inside it
i have some problems with PPI module: assume i have Foo.pm: package Foo; sub
my problem is as follows: Assume that we have the following file: package p;
Let's assume I have a python package called bestpackage . Convention dictates that bestpacakge
Assume I have the following ; def test(): while 1: a = b time.sleep(60)
Assume I have one threadpool and each thread is running following method: void runMe(HashMap
I have installed the latest hg package available for Fedora Linux. However, hg clone
Let's assume I have a package which calls an executable file somewhere in the
Assume I have a class. package org.my.domain; public class BestClassEver{} My Workflow Through some

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.