title: Can a python script persistently change a Windows environment variable? (elegantly)
body: <p>Following on from my <a href="https://stackoverflow.com/questions/488294/how-can-i-make-a-windows-batch-file-which-changes-an-environment-variable">previous question</a>, is it possible to make a Python script which persistently changes a Windows environment variable? </p>
  
  <p>Changes to os.environ do not persist once the python interpreter terminates. If I were scripting this on UNIX, I might do something like:</p>
  
  <pre><code>set foo=`myscript.py`
  </code></pre>
  
  <p>But alas, cmd.exe does not have anything that works like sh's back-tick behavior. I have seen a very long-winded solution... it 'aint pretty so surely we can improve on this:</p>
  
  <pre><code>for /f "tokens=1* delims=" %%a in ('python  ..\myscript.py') do set path=%path%;%%a
  </code></pre>
  
  <p>Surely the minds at Microsoft have a better solution than this!</p>
  
  <p><strong>Note</strong>: exact duplicate of <a href="https://stackoverflow.com/questions/488366/how-do-i-make-environment-variable-changes-stick-in-python">this question</a>.</p>