0

I'm using Python 3.6, and I have a global settings file built using a Python dotenv library.

I'd like to import this file as needed in various nested packages and directories. Note that I don't mean proper subpackages, since in most cases these are independent modules. Here's the directory structure with an explanation of the contents:

app/ # Flask app (a package)
db/ # Database setup via Alembic (contains a package)
shovel/ # Python tasks via Shovel library (not a package)
scripts/ # Misc Python scripts (not a package)
settings.py # Settings file

I know I could do something like this to import the file by its path, but it seems incredibly clunky and improper to do that across umpteen files.

fny
  • 31,255
  • 16
  • 96
  • 127
  • Out of curiosity, what is your final intent? Are you trying to access the environment variables through dotenv from any python module within the described directory structure? – Bastian Aug 10 '17 at 21:30
  • Is it something you want to distribute? If you only need it on your system, could you put it somewhere on your python path? So import would always find it. – Bastian Aug 10 '17 at 22:04
  • Yes, I'm trying to access the environmental variables through dotenv, preferably with defaults provided. For example, `MYSQL_HOST = os.environ.get('MYSQL_HOST', 'localhost:3306')`. And no, I'm not intending to distribute it as a package, but I'm not too keen on relying on adding it the python path, since it may cause conflicts with for the other developers working on the project. – fny Aug 11 '17 at 03:15

0 Answers0