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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:06:05+00:00 2026-06-04T02:06:05+00:00

I am trying to refactor my code (a bunch of core modules and some

  • 0

I am trying to refactor my code (a bunch of core modules and some apps living in a common directory).
I want to get this structure

Root
   __init__.py
   Core
       __init__.py
       a.py
       b.py
       c.py
   AppOne
       __init__.py
       AppOne.py
   AppTwo
       __init__.py
       AppTwo.py
   AppThree
       __init__.py
       AppThree.py

where AppOne.py, AppTwo.py and AppThree.py imports the modules a, b and c in the Core package.

I don’t understand how to write the __init__.py files and the import statements. I have read
http://docs.python.org/tutorial/modules.html and http://guide.python-distribute.org/creation.html. I got errors like “Attempted relative import in non-package” or “Invalid Sintaxis”

  • 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-04T02:06:06+00:00Added an answer on June 4, 2026 at 2:06 am

    You need to add the directory of the python modules to sys path.

    If you have something like this

    Root
       here_using_my_module.py
       my_module
           __init__.py  --> leave it empty
           a.py
           b.py
           c.py
    

    You need to add you module directory to sys_path

    //here_using_your_module.py
    import os, sys
    
    abspath = lambda *p: os.path.abspath(os.path.join(*p))
    
    PROJECT_ROOT = abspath(os.path.dirname(__file__))
    
    sys.path.insert(0,PROJECT_ROOT)
    
    import a from my_module
    
    a.do_something()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to refactor some delphi 7 code. One of the procedures I'd
I've got this piece of legacy code which I'm trying to refactor at the
I am trying to refactor some code in an ASP.Net website and having a
I am trying to refactor some code while leaving existing functionality in tact. I'm
I'm trying to refactor some code and move some of my before_filter's from the
I'm quite new to smart pointers and was trying to refactor some existing code
I'm new to javascript and was trying to refactor some code, clearly there's something
I'm trying to refactor some legacy code to use Spring to handle the jms
I'm trying to refactor some code here that was done previously by other guys,
I'm trying to refactor this code. I have this jquery ajax call $.ajax({ url:

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.