About a plugin framework!

Guyon Morée gumuz at NO_looze_SPAM.net
Tue Jun 8 11:41:43 CEST 2004


Hi,

change: cn = pxml.GetClassname()
into: cn = globals()[pxml.GetClassname()]


your line returns a string, the name of your class, which is not callable
the correct line looks up the name in your globals() dict and returns a
callable.


cheers,
guyon

==========================================================
"Simon Roses Femerling" <simonroses at granisla.com> wrote in message
news:mailman.693.1086683764.6949.python-list at python.org...
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





More information about the Python-list mailing list