Calling constructor of unknown classes

Lars Heuer python at quixs.com
Sat May 8 08:48:21 EDT 2004


Hi all,

I try to do the following:

  map = {'some.thing':'ClassName'}

  try:
    mod = __import___(map.keys()[0], {}, {}, map.values()[0])

    # Now I want to return an instance of the class in
    # map.values()[0]

    # I've to do something like "return mod.(map.values()[0])()"


How to return the instance of the 'unknown' class? I've only the name
as string. I tried eval, but I don't get it work.

Thanks,
Lars





More information about the Python-list mailing list