I need to assign a different value to a variable if an env variable called 'MYPROJECT_PRODUCTION' is set to True.So ,I created the following code in which I created a module1 file for storing the production values
The main code resides in mycode.py.Here is the directory structure
mypythondir/
mycode.py
module1.py
mycode.py
import os
if __name__=='__main__':
MYNAME='denny'
if os.environ.get('MYPROJECT_PRODUCTION',True):
from module1 import *
print 'myname=',MYNAME
module1.py
MYNAME='damon'
I opened a terminal (in ubuntu) Just to check I ran
mypythondir$echo $MYPROJECT_PRODUCTION
Empty output..So,no variable set yet. Without setting the env variable ,ran mycode.py from mypythondir
mypythondir$python mycode.py
mypythondir$myname= damon
I am confused,why is the value 'damon'.It should be 'denny' since there is no MYPROJECT_PRODUCTION set ,and there is no key 'MYPROJECT_PRODUCTION' in os.environ.
Then I set
mypythondir$export MYPROJECT_PRODUCTION=False
Again I ran the code and even now the result is the same..but this time the key MYPROJECT_PRODUCTION is in os.environ
What is happening here ? Can someone please help me figure this out?