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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:19:37+00:00 2026-06-10T13:19:37+00:00

Ok, let’s give you an example (original question below). I have made a package

  • 0

Ok, let’s give you an example (original question below).

I have made a package called “myproject” which shows the problem I’m facing.

  1. Download the package here: https://dl.dropbox.com/u/11013311/myproject.zip
  2. Install the package (eg.: sudo python setup.py develop)
  3. open an Ipython session and type: “import myproject”
  4. if you start typing “myproject.” and hit tab twice to get the available methods/values…, you’ll see “myproject.myproject” which himself shows the same problem.

Is one of you guys able to explain me what I’m doing wrong? The answer from Andrew Alcock do not help me to fix it, or at least I don’t see where could be the problem.

Of course, with such a simple example, there is no need for the package __init__.py file to be that complex, but in my real project I do need COOL instance to be accessible via myproject.COOL.

Thanks for your answers!

EDIT: I’ve awarded utapyngo the bounty because his solution is effective and I’ve learnt something more (relative imports with deep submodules). But I’d like to thanks Andrew and nehz for their answers (nehz also provided a solution that fixed my problem, but very subjectively I find it ‘less beautiful’ ; and Andrew provided useful advices). Too bad I can’t share the bounty.

**

ORIGINAL QUESTION:

**

I’m not sure I’ve phrased correctly the question. I have created a large code with a number of sub-packages, and for simplicity let’s call it ‘CODE’.

The problem is: ‘CODE’ appears in the namespace so I can have CODE.CODE or CODE.CODE.CODE, etc… an infinite number of times which looks strange to me and is probably (I guess) a hint that something is wrong (although the code works perfectly without warning).

I guess the problem has something to do with my __init__.py and the structure of my code, so I give some more informations here.

Simplified code structure:

CODE
  | __init__.py
  | tools
     | __init__.py
     | mytools.py
  | other
     | __init__.py
     | init.py
  | sub
     | __init__.py
     | module.py

File: __init__.py (the first one, at the root of CODE)

import CODE.tools.mytools as MyTools
import CODE.other.init

OBJ = CODE.other.init.function()
...

The file mytools.py do not import OBJ from CODE, or any other module that may import OBJ.
init.py may import modules such as mytools.py.
Finally, modules like module.py may import either mytools.py or OBJ (from CODE). Usually, all import are made with absolute import, such as in: from CODE.sub.module import func.

Does anyone have an explanation for such a behavior? I did not find any related question on SO, but it may be due to the wrong phrasing of mine.

  • 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-10T13:19:39+00:00Added an answer on June 10, 2026 at 1:19 pm

    In your main __init__.py you don’t have to and even should not reference your module name (who knows, you would probably want to rename it in future).

    Just replace

    import myproject.mymodule_...
    

    with

    import mymodule_...
    

    Now there is no myproject.myproject:

    >>> dir(myproject)
    ['COOL', 'SubY', '__builtins__', '__doc__', '__file__', '__name__', '__package__',
     '__path__', '__version__', 'atexit', 'exit_report', 'mymodule_one', 'mymodule_two',
     'obj', 'toto']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's take a common example how a haskell function can be called from a
Let's say, we have and list of objects in variable called articles, each object
Let's say I have a queue called notifications and I post 1000 messages to
Let's say I have a dataset, which can be neatly classified using weka's J48
Let give you the details of this rather odd issue. We have a very

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.