I have a file, settings.py
that looks like this:
import sys
import socket
import os
comp_name = socket.gethostname()
if comp_name == 'mymachine.local':
DB_VAR=os.environ.get('ENV_VAR')
else:
print 'update settings.py with global variable names for this machine'
sys.exit(1)
ENV_VAR
is an environmental variable from the OS (I'm on OSX). I've confirmed that manually calling os.environ.get('ENV_VAR')
from within the shell gives me the desired output.
The file execution.py
lives in the same directory as settings.py
and has the statement import settings
in the header. print settings.comp_name
returns the value 'mymachine.local'
, but print settings.DB_VAR
returns the error:
AttributeError: 'module' object has no attribute 'DB_VAR'
Basically, I need to control which values are passed to these variables depending on the environment that the code is being run. Any pointers on what I'm doing wrong here would be very much appreciated.