Calling a function of a module from a string with the function's name in Python shows us how to call a function by using getattr(“bar“)(), but this assumes that we have the module foo imported already.
How would would we then go about calling for the execution of “foo.bar” assuming that we probably also have to perform the import of foo (or from bar import foo)?
Use the
__import__(....)function:http://docs.python.org/library/functions.html#import
(David almost had it, but I think his example is more appropriate for what to do if you want to redefine the normal import process – to e.g. load from a zip file)