dynamic module loading via __import__, nonetype?



Hi all,

I'm trying to create a setup which allows a program to request an object
using strings and get an object of that type. It appears to be mostly
working but i have difficulties if i attempt to load a module at runtime
and then request an object of that type.

Essentially, my code works as follows:

I have a registry class which has a method to register a class. It
inserts an entry into a dictionary using a tuple of two strings (read
from attributes of the class) that points to the class. It also has a
method which will create an object of that class type which takes two
strings as an argument.

Every class i want to use this technique inherits from a class which
uses a custom metaclass. The custom metaclass' __init__ function
registers them with the registry class.

The registry class has another method which allows you to specify a path
to place your plugins in. In reality it merely appends this string to
sys.path. The registry "create" function has a little extra smarts in
that if it can't find the class already in the dictionary, it will
attempt to load the appropriate module. It does this by using __import__
and uses the two strings supplied with a dot in between as the module name.

If i manually import a module, this method works a treat, however if i
attempt to dynamically load a module at runtime the create method fails
with the following error:

TypeError: 'NoneType' object is not callable

I can see that the module is getting imported as i have set print
statements in the custom metaclass to let me know when it is registering
a new class. I can only conclude then that there is some difference
between using the import statement and the __import__ function.

I don't want to clutter the mailing list so i haven't attached any code,
but i certainly can supply it assuming the answer isn't something
obvious i've missed. Am i going about this completely the wrong way? Is
there already an established approach for an auto-registering,
dynamically loading plugin setup? Any help greatly appreciated.

I'm not subscribed to the list, so please cc me in any replies.

Thanks,

John Allman
.



Relevant Pages

  • The certification password of Internet Explorer 7 and operation of auto complete
    ... About the certification password of Internet Explorer and operation ... By remembering the strings that are input in the following text ... In this registry, there are values whose name is a string of 42 bytes ... We cannot guess the original strings from the hash value, ...
    (Bugtraq)
  • Help with MAPI properties please.
    ... I've got a problem with MAPI properties. ... DoConfigPropsheet does an OpenProperty on the data associated with the ... UNICODE are not defined; all strings ... // The code enumerates registry entries, ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Windows XP Welcome Screen
    ... assigning a password should prevent automatic logon. ... Microsoft MVP [Windows XP Shell/User] ... After I deleted all the strings in the registry, ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Windows XP Welcome Screen
    ... Configuration that worked. ... Once you are at the desktop, use your Browser and ... After I deleted all the strings in the registry, ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: OT: Guitar setup and repair
    ... time is to get into doing guitar setup and repair. ... appointments to assess issues and perform a basic setup on a guitar. ... customer pays for strings ... customer pays for strings... ...
    (rec.music.makers.guitar.jazz)