calling method on dynamically loaded module

Eric Cifreo ecifreo at austin.rr.com
Mon Nov 26 17:02:10 EST 2001


Hello all,

I'm trying to dynamically load a set of modules and then call a specific
method on each one.  For now there's only one module in the list.
The module seems to be loading correctly, but then the method is not found.
There IS a 'perform' method defined in the loaded module.

I have the following code snip:
#####
for mod in self._modules:
    (fp, pathname, descrip) = imp.find_module(mod)
    mymod = imp.load_module(mod, fp, pathname, descrip)
    print ">>>>> my mod is", mymod
    meth = getattr(mymod, "perform")
    print "getattr returned", meth
    meth()
    print ">>>>> Called perform"
#####

When it executes, I get:
#####
>>>>> my mod is <module 'snmp_mod' from 'snmp_mod.pyc'>
exceptions.AttributeError 'snmp_mod' module has no attribute 'perform()'
#####

Is there any way to do this?

Thanks,

Eric Cifreo
Austin, TX





More information about the Python-list mailing list