In application no.1 I have a settings.py file, and a utils.py, which contains the following:
from application_one import settings
def someFunction():
// do some logic here based on imported settings
Then in application no.2 I do:
from application_one.utils import someFunction
In application no.2 I have a local settings.py and when I import ‘someFunction()’ I want to use the local settings.py not the file from application no.1. So how would one overide the import in application no.2?
You can do the following:
(this lets
someFunction()use the Application 1 settings by default) and then call it from Application 2 by sending the local settings:One advantage of this approach is that your code in both Application 1 and 2 explicitly shows that
someFunction()gives results that are setting-dependent.