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
  • 70,285
  • 16
  • 125
  • 181
twneale
  • 2,736
  • 3
  • 25
  • 32
  • 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
  • 811,175
  • 162
  • 1,198
  • 1,373