About a plugin framework!

Simon Roses Femerling simonroses at granisla.com
Tue Jun 8 10:40:41 CEST 2004


Dear pythonnians :)

Hopeful somebody can help me about implementing plugin support.

I'm working on a python/wxpython app that needs plugin support. My problem is:

The way my app works is a python module (plugin) that contains (imbedded) XML defining
the classname and some extra information and the app will be load the module using the classname:

Example:

------ mymodule.py ----

__xml__ ="""
    <data>
        <classname>Test</classname>
    </data>
"""

class Test:
    def Msg(self):
        print "Hello"

---------------------------------

--- MyApp.py -----------

fp = open(f)            
 exec(fp) in globals()
str = __xml__
pxml = parsexml.ParseXML()
pxml.BeginParse(str)
cn = pxml.GetClassname()
mymod = cn()   <-- Here is the error
mymod.Msg()

----------------------------------

The error is:

Traceback (most recent call last):
  File "blackout.py", line 503, in onAttackMod
    mymod = cn()
TypeError: 'unicode' object is not callable

Any suggestions ? How can achieve this ?
Each module (plugin) can have a different class name defined in the XML data.

Besides this anyone have suggestions for a better plugin framework ? Maybe using imp module to dynamically import
modules ?

Any examples ?

Thx for any help!

Sincerely

SRF
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040608/ef5f4a9e/attachment.html>


More information about the Python-list mailing list