How to import a module programmatically

To import a module where you have the module name as a string and want to do it programmatically:

X = import(‘X’)

X is now a variable that can be used in your code:

e.g. getattr(X, method)