Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to load plugins as objects?

Reply
Thread Tools

How to load plugins as objects?

 
 
censored
Guest
Posts: n/a
 
      05-28-2005
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?
 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      05-28-2005
"censored" <(E-Mail Removed)> 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>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
eval versus load and plugins Rover Rhubarb Ruby 3 07-27-2007 07:31 PM
How to swap plugins/extensions between 2 computer / various version of Mozilla Firefox? Chaos Master Firefox 0 07-10-2004 05:00 AM
plugins Davide Laneri Firefox 1 01-29-2004 09:46 AM
Java Plugins and Mozilla Doug Firefox 0 08-08-2003 05:52 AM



Advertisments