Possible Duplicate:
from . import xusing__import__?
How does one do the equivalent ofimport * from modulewith Python's__import__function?
How would I do the from … import * with the __import__ function?
The reason being that i only know the name of the file at runtime and it only has 1 class inside that file.
Don’t. Just don’t. Do I need to explain just how horrible that it? Dynamically importing (though sometimes inevitable) and importing into global namespace (always avoidable, but sometimes the easier solution and fine withtrusted modules) are bad enough themselves. Dynamically importing into global namespace is… a nightmare (and avoidable).
Just do
_temp = __import__(name, globals(), locals(), [name_of_class]); your_class = _temp.name_of_class. According to the docs, this is about what from name import name_of_class would do.