Setting the environment variable of liking is rather simple, giving the name and the value for a single environmental variable would be something along these lines:
Using the command line
import os
import sys
var_name = sys.argv[1]
var_value = sys.argv[2]
os.environ[var_name] = var_value
Just execute your script from the command line as:
my.script ENV STAGE
This can be verified as follows within python:
var_name in os.environ #python3
os.environ.has_key(var_name) #python2
Interactively
Using a while construct in the script
import os
while True:
env_var = input("Enter ENV (name:value), type 'done' to exit: ")) #enter var:value
if env_var.lower() == "done":
break
try:
var, val = env_var.split(":")
except:
print ("Wrong input format! name:value required.")
continue
os.setenv[var] = val