1

In my terminal, I run

echo $X

And an empty line is printed because the environment variable X is not defined.

Then I run this python code:

import os
os.environ['X']='Y'

Exited the python console, and checked the value of X again

echo $X

Yet, X is still undefined, what am I doing wrong ?

Uri Goren
  • 13,386
  • 6
  • 58
  • 110
  • 2
    You are defining the variable in a subshell, so when you exit it you lose the value. – fedorqui Jul 16 '15 at 13:38
  • How can I make the value stay defined after the python shell terminates ? – Uri Goren Jul 16 '15 at 13:41
  • As fedorqui said, you're only setting the environment variable within the scope of the Python environment, so it evaporates once you leave the console. [This question may help you.](http://stackoverflow.com/questions/716011/why-cant-environmental-variables-set-in-python-persist) – SuperBiasedMan Jul 16 '15 at 13:41

0 Answers0