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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:08:25+00:00 2026-05-20T08:08:25+00:00

First, it seems proper to me to state that I’ve read over the following

  • 0

First, it seems proper to me to state that I’ve read over the following questions:

  • Python imports by folder module
  • Dynamic module import in Python

And, I don’t feel like they address my use case. That said, here’s my question:

How can I dynamically import from a configuration file like this:

[imports]
/var/imports/foo.py = baz monkey
/var/imports/bar.py = ape

So that I can call the known objects via RESTful interface like this.

# http://localhost/data?operation=get&class=baz&id=1
def handler(object):
  def handle(self):
    cls = instantiate(request.args["class"])
    meth = request.args["operation"]
    return getattr(cls,meth,request.args)

And it could respond with the result of get() on an instance of that class.

  • 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-20T08:08:26+00:00Added an answer on May 20, 2026 at 8:08 am

    Here’s a rough sketch of a class registry you could use like this:

    class ClassRegistry(object):
    
        def __init__(self):
            self.classes = {}
    
        def add_file_classes(self, fname, class_list):
            globals = {}
            exec open(fname) in globals
            for class_name in class_list:
                self.classes[class_name] = getattr(globals, class_name)
    
        def get_class(self, class_name):
            return self.classes[class_name]
    

    Read your config file and invoke add_file_classes like this:

    reg = ClassRegistry()
    reg.add_file_classes("/var/imports/foo.py", ["baz", "monkey"])
    reg.add_file_classes("/var/imports/bar.py", ["ape"])
    

    then later:

    cls = reg.get_class("baz")
    

    Note that we aren’t actually importing the files, simply executing them and collecting their results.

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

Sidebar

Related Questions

In the following examples: the first seems more verbose but less wasteful of resources
Because this is my first attempt at an extension method that seems quite useful
When I run the following code, it only seems to be downloading the first
I have a treeview that utilizes the StateImageList to implement proper tri-state checks in
(first of all, it seems this is a subject that is discussed many times
http://dspace.dial.pipex.com/town/green/gfd34/art/bloopers.html The first one seems simple; return strcpy(malloc(strlen(s)), s); malloc could return null ,
First, I've taken the time to review this question which seems to be the
Just trying to confirm an impression: it seems enums in EF5 + Code First
This is the first time I've used a 3rd party jar, but it seems
I can't possibly be the first person to do this, it seems like it

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.