1

Possibly a stupid question: Why can't I set an environment variable with this?

os.system('set foo=bar') # on windows

I'm aware of os.environ, and that works for me. I'm just confused about why the former doesn't work.

Chris Lutz
  • 73,191
  • 16
  • 130
  • 183
twneale
  • 2,836
  • 4
  • 29
  • 34
  • Possible duplicate: http://stackoverflow.com/questions/1506010/how-to-use-export-with-python-on-linux – amcnabb Jul 10 '13 at 19:56

1 Answers1

11

See the discussion here -- export and set are both shell commands, and whether on Windows or Unix, they're still inevitably being addressed to a child process running the shell (be it bash, cmd.exe, whatever) and so bereft of any further action when that child process terminates (i.e., when os.system returns to the caller).

Community
  • 1
  • 1
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395