There is path 'lookup/lookup_files' where my lookup files are present. The name of the files are standardized as productname1_lookup.py, productname2_lookup.py, productname3_lookup.py and so on. Now instead of importing all the files normally I am wanting to import and load the lookup file based on the product name dynamically during the run-time itself. Can anyone please help me to achieve this. I lised down all the files in the given path by using os.listdir but I am unable to understand how I could import. Any help would be really helpful. Thanks in advance.
Asked
Active
Viewed 72 times
1 Answers
0
Let's say your module name is stored in a variable modulename
during runtime. Example
new_module = __import__(modulename)
Reference: importing a module when the module name is in a variable

Akshath Mahajan
- 248
- 2
- 11