'Python: Dynamic Access of Data in Module at Runtime

I have a Python file (myconstant.py) that does not exist when I start my program. It also is located on another machine, but I can access it via Samba. Let's say in it is:

MYCONSTANT1 = 123

My program should be able to access this constant at runtime. I think I need some kind of wrapper, e.g. constant_wrapper:

from myconstant import *

Now I can use constant_wrapper.MYCONSTANT1 in my main program. This unfortunately only works if myconstant.py exists at the beginning of the execution.

How can I dynamically load myconstant.py at runtime without having to write a class that server as some kind of getter but directly accessing the data in it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source