Let’s suppose you have a module named “module” inside a hirearchical “folder2” with a class named “klass”.
How can I get the class like in a square bracket syntax?
module = __import__('folder1.folder2.module', fromlist='*')
sbs_module = module['klass']
#lets say we print a value from the method getValue
print sbs_module.getValue()
Replace this line:
with this line:
The reason for that is that you need to refer to module variables (in this case variable named
klass) by using dot notation, not by accessing the variables by keys.Alternatively you can use two different notations:
by key:
by attribute:
but I do not recommend it unless absolutely necessary.