Say I'm storing settings in a Python file, like so:
#!/usr/bin/env python
#
# settings.py
import os
LOG_DIR = '/tmp'
LOG_FILE_MAIN = os.path.join(LOG_DIR, 'main.log')
Now, I include that file like so and change one of the values:
#!/usr/bin/env python
#
# main.py
import settings
settings.LOG_DIR = '/home/myuser'
When I print out a variable that relies on a (now changed) "reference" variable, I'll see that the value hasn't changed.
print(settings.LOG_FILE_MAIN)
Will return:
/tmp/main.log
Instead of:
/home/myuser/main.log
I understand why this is (Python has already calculated the strings value), but I need to work around it. Is there a way to achieve the desired result, other than creating a class and overriding the __setattr__
function?