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?
Your shell command can be
BEAR_NAME="sleepybear" python hello.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With