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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:27:00+00:00 2026-06-11T01:27:00+00:00

I am writing a simple scheduling service. I don’t want to hard-code all of

  • 0

I am writing a simple scheduling service. I don’t want to hard-code all of the tasks it can schedule and instead would like to support plugins that can be dropped in a folder and loaded dynamically at runtime.

My plan is to have a JSON file (or any configuration file) that maps a task name to the location of a Python file (a module) which will have a class called Plugin. Pretty simple I thought. When someone schedules a task to run, they pass the task name and the time to run it. When the time elapses, the plugin is loaded (or reloaded) and is ran with any additional arguments passed to the scheduler.

I have been looking at the imp module to see how to load modules at runtime. I am not sure whether I want to list plugins using their physical location (file system path) or to use their module names like you’d see in a import statement. It seems imp wants to use physical location.

I got two different versions of this code “working”. Here is one that uses importlib:

    pluginName = self.__pluginLookup[pluginName]
    module = import_module(pluginName)
    module = reload(module)  # force reload

    plugin = module.Plugin()
    return plugin

This is one I wrote using imp:

    path = self.__pluginLookup[pluginName]
    path, moduleName = split(path)
    moduleName, extension = splitext(moduleName)

    file, path, description = find_module(moduleName, [path])
    with file:
        module = load_module(moduleName, file, path, description)

    plugin = module.Plugin()
    return plugin

The problem I am running into is handling dependencies. If I have a plugin.py file that depends on a dependency.py file in the same folder, saying import dependency doesn’t seem to work. Instead, it looks up the dependency from the PYTHONPATH.

How can I make the imports relative to the plugins themselves?

  • 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-11T01:27:01+00:00Added an answer on June 11, 2026 at 1:27 am

    You could append path to sys.path:

    import sys
    sys.path.append(path)
    

    where path is the directory containing the dependency.py.

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

Sidebar

Related Questions

I'm writing a simple OpenGL application that uses GLUT . I don't want to
I'm looking into writing simple graphics code in Android and I've noticed some synchronized()
I'm writing simple filter in Android and want to use ExpandableListAdapter with check boxes.
I'm writing a simple class in C++ for a class (school, not code). I
I'm writing a simple C# program and want to use an SQL server to
I'm learning Rails by writing simple TODO tasks aplication. Two models are: class List
I am writing simple, unsophisticated web-server code in java. It seems to be finished,
I am writing simple hex engine for action-rpg in XNA 3.1. I want to
Basically I am writing a simple bit of code to increment every one second
I am writing simple program for my Ubuntu 10.04. I want to see which

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.