I want to decide project's status (production/development) by checking if there is a PRODUCTION
environment variable.
The problem is that, surprisingly, this code returns True
when there is no PRODUCTION
environment variable:
PRODUCTION = True if os.getenv('PRODUCTION', False) in [0,"0"] else False # !!! In Bash, 0 means true and 1 false
The thing is that False in [0,"0"]
gives True
which I didn't know until now. I know that if 0
is the same as if False
but this surprised me.
How to make it work and why it behaves like that?
EDIT
Solved this way but I'm still curious why the "in" statement works like that.
PRODUCTION = True if str(os.getenv('PRODUCTION', 1)) == "0" else False # !!! In Bash, 0 means true and 1 false