initialising a class by name
krmane at gmail.com
Wed Jan 14 08:49:23 CET 2009
On Tue, 2009-01-13 at 21:51 -0800, Chris Rebert wrote:
> Assuming all the classes are in the same module as the main program:
> instance = vars()[class_name](args, to, init)
The classes are not in the same module.
Every glade window is coupled with one py file (module) containing one
class that has the events for the glade file.
Inshort, there is one class in one module and they are all seperate.
> Assuming the classes are all in the same module "mod", which is
> separate from the main program:
> instance = getattr(mod, class_name)(args, to, init)
Can you explain the difference between getattr and var()?
More information about the Python-list