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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:37:07+00:00 2026-05-26T18:37:07+00:00

I have the following folder structure: – MyProject – App1 – some_module1.py – some_module2.py

  • 0

I have the following folder structure:

- MyProject
    - App1
        - some_module1.py
        - some_module2.py
    - App2
        - some_other_module1.py
        - some_other_module2.py

Inside each of the modules (some_module1.py for example) there is a class that extends from a base class, in my case, Producer.

What I am trying to do is dynamically load in this class. To do that, I have a list of “installed apps” that looks like this:

INSTALLED_APPS = (
    'App1',
    'App2',
)

I am trying to write a function that will check each “app” package for a particular producer class and ensure it extends from the producer base class. Something like this:

module_class = 'some_module1.SomeClass'

# Loop through each package in the INSTALLED_APPS tuple:
for app in INSTALL_APPS:
    try:
        #is the module_class found in this app?
        #App1.some_module1.SomeClass - Yes
        #App2.some_module1.SomeClass - No

        # is the class we found a subclass of Producer?
    exception ImportError:
        pass

I’ve tried experimenting with imp and importlib, but it doesn’t seem to handle this kind of import. Is there anyway for me to be able to achieve this?

  • 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-26T18:37:08+00:00Added an answer on May 26, 2026 at 6:37 pm

    You may want to have a look at:

    • __import__() to import modules knowing their name as string;
    • dir() to get the names of all the objects of a module (attributes, functions, etc);
    • inspect.isclass(getattr(<module ref>, <object name>)) to identify classes among the objects of a module;
    • issubclass() to identify sub-classes from a given class, as explained here.

    With these tools, you can identify all classes in a given module, that are inheriting a given class.

    I’m using this mechanism to dynamically instantiate classes from given module, so that their updates are automatically taken into account at an upper level.

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

Sidebar

Related Questions

I have the following folder structure TempProj !-js !-jsp !-WEB-INF !-classes !-lib Inside my
Suppose I have the following (desired) folder structure: *CommonProject *Project#1 ----> CommonProject(link) *Project#2 ---->
I have the following directory structure of a project: Folder project in Eclipse: --folder
Trying to get a simple test perl script working. Have the following files/folder structure
I have a folder structure that contains multiple javascript files, each of these files
I have the following folder structure: FolderA --Folder1 --Folder2 --Folder3 ... --Folder99 Folders 1
I have simple application with following folder structure: ProjFolder |-----src |----------packagename |---------------{sourcefiles} |----------META-INF |---------------{beans.xml}
Lets say we have the following file and [folder] structure in a project with
I am a newbie in this department.I have following folder structure root root\html root\html\html
I have the following folder structure, and I would like for svn to ignore

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.