How to load plugins as objects?

Discussion in 'Python' started by censored, May 28, 2005.

  1. censored

    censored Guest

    Hi. I'm hoping for a bit of programming guidance here ....

    I have an application I wrote (it's an irc bot fyi), with which I want to
    use plugins.

    Basically, I want there to be directory called plugins/ .

    In plugins, there should be a bunch of *.py files. Each file should
    contain a single class.

    When the application launches, I want the interpreter to scan the
    plugins/ dir for *.py files, and load each class in each every *.py file
    as an object an object in memory.

    I want it to so that every time I want the app to perform a new function,
    I just write a plugin and stick it in the plugins/ directory.

    What's the easiest way to go about this?
     
    censored, May 28, 2005
    #1
    1. Advertising

  2. "censored" <> wrote:

    > Hi. I'm hoping for a bit of programming guidance here ....
    >
    > I have an application I wrote (it's an irc bot fyi), with which I want to
    > use plugins.
    >
    > Basically, I want there to be directory called plugins/ .
    >
    > In plugins, there should be a bunch of *.py files. Each file should
    > contain a single class.
    >
    > When the application launches, I want the interpreter to scan the
    > plugins/ dir for *.py files, and load each class in each every *.py file
    > as an object an object in memory.
    >
    > I want it to so that every time I want the app to perform a new function,
    > I just write a plugin and stick it in the plugins/ directory.
    >
    > What's the easiest way to go about this?


    for file in glob.glob("plugins/*.py"):
    ns = {}
    execfile(file, ns)
    for name, object in ns.items():
    # pick out interesting objects

    </F>
     
    Fredrik Lundh, May 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ThunderMusic

    Plugins and Late Binding

    ThunderMusic, Jan 27, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    865
    Patrice
    Apr 12, 2005
  2. Philip Townsend

    detecting plugins / ServerVariables

    Philip Townsend, Feb 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    313
    Eric Lawrence [MSFT]
    Feb 22, 2004
  3. sleem
    Replies:
    1
    Views:
    401
    Sybren Stuvel
    Aug 15, 2006
  4. 7stud
    Replies:
    11
    Views:
    714
    Dennis Lee Bieber
    Mar 20, 2007
  5. Rover Rhubarb

    eval versus load and plugins

    Rover Rhubarb, Jul 27, 2007, in forum: Ruby
    Replies:
    3
    Views:
    111
    Giles Bowkett
    Jul 27, 2007
Loading...

Share This Page