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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:37:50+00:00 2026-05-16T06:37:50+00:00

I am trying to keep a somewhat organized directory structure as I plan to

  • 0

I am trying to keep a somewhat organized directory structure as I plan to add more and more scripts. So lets say I have a structure like this:

/src/main.py
/src/db/<all my DB conn & table manipulation scripts>
/src/api/<all my scripts that call different APIs>

My main.py script will include certain classes from db & api folders as needed. I have the blank _____init_____.py files in each folder so they are included fine. But say I want to include a class from the db folder in a script in the api folder? Like I would need to back up one dir somehow? The api scripts fail when I have a line like this in them:

from db.Conn import QADB

I am on v2.6.

Update: I have tried a relative import, but get this?

from ..db.Conn import QADB 
     ^ SyntaxError: 
invalid syntax
  • 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-16T06:37:51+00:00Added an answer on May 16, 2026 at 6:37 am

    The way you have it setup is creating three different modules – this may or may not be what you want to do. If you want a common module which can manage different tasks you could arrange it as follows:

    mymodule
     |- __init__.py
     |--database
     |   |- __init__.py
     |   |- dbclasses.py
     | 
     |--api
     |   |- __init__.py
     |   |- apiclasses.py
     |
     |--other
    
    [etc]
    

    If you have it like this and want to use the API and database functionalities, you can start by saying:

    from mymodule.database.dbclasses import MyDBClass
    from mymodule.api.apiclasses import MyAPIClass
    

    Notice the way you had it: the name of your top “module” was src (it was not a module because it did not have an __init__.py file).

    If you use many common functionalities in the top module (from either submodule) you can include them in the top __init__.py and simply call from mymodule import MyDBClass, MyAPIClass.

    Contents of top __init__.py:

    from mymodule.database.dbclasses import MyDBClass
    from mymodule.api.apiclasses import MyAPIClass
    __all__ = ['MyDBClass', 'MyAPIClass']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.