What is a pythonic way of specifying which class to import using config file and variable names
user42406 Published in September 19, 2018, 9:07 am
I have written a JSON config file that lists all the inputs for running a package. That package, though, has several classes that are interchangeable. What is a pythonic way to define the imports from within the config file?
if config.import_name == 'class_one':
from config.class_one_location import config.import_name as class
if config.import_name == 'class_two':
from config.class_two_location import config.import_name as class
As such, I can't do this because the import function doesn't accept variable names. I also don't believe I can use __import__ because I need to specify both the path and the module name within that path, although I may be misunderstanding.
python json class import
share|improve this question
edited Feb 12 at 17:44
asked Feb 12 at 16:46
Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.
Browse other questions tagged python json class import or ask your own question.