I am trying to use a *.py file to take variables from and use them across multiple imports in my python application, similar to how a Django settings file works.
An example settings file:
DB_NAME = 'foo'
DB_TABLE = 'bar'
#Lots of other variable names and values here
The benefit is that I can load different settings very quickly this way. I can reference a sort of global “DB_NAME” wherever I want without having specific objects to deal with.
The drawback is that I have to change the import statement in every file that has to import them.
Can I set it up so that I import the file once and then reference a generic import to get all of these values?
Or is there a much better way to do this?
Any help is appreciated.
EDIT: The problem stems from having multiple settings files. I would have to import settings.py for one file, or if I want a different settings file, I would need to change all the import statements to reference test_settings.py, etc..
I don’t want to manually change the import locations in order to change what is imported across the entire application.
create our own config.py file in a folder
open shell (ipython)
don’t forget your __init__.py file !