Issue
If I have a python scripts with simple lines as the following:
import os
name = os.environ.get('BEAR_NAME')
if name != "":
print("hello, ", name)
I'd like to set a temporary environment variable when running this script. Note that if I do
export BEAR_NAME="sleepybear"
python hello.py
the env var BEAR_NAME
will still have value sleepybear
once the python program finishes, which is not desired.
Take docker's example, we can do docker run -e SOME_VAR=SOME_VAL
to set the environment variable SOME_VAR
. Is there a similar way when running a python script?
Solution
Your shell command can be
BEAR_NAME="sleepybear" python hello.py
Answered By - ogdenkev Answer Checked By - Cary Denson (WPSolving Admin)