[Tutor] Re: How to change Windows Environment Variable

Tim Roberts timr at probo.com
Tue Oct 30 01:35:03 EST 2001


dman <dsh8290 at rit.edu> wrote:
>|
>| Bad news:
>| 
>| There is no SetEnvironmentVariable() function.
>
>See the 'os' module.
>
>>>> import os
>>>> print os.putenv.__doc__
>putenv(key, value) -> None
>Change or add an environment variable.
>>>> 
>
>The 'os.environ' attribute is a dict containing all the environment
>variables.

However, that information does not help the original poster.  os.putenv
(which is actually disrecommended in favor of directly writing to the
os.environ dictionary) only affects the environment we pass to our child
processes.  When you exit Python, all your os.environ changes go away.  The
Win32 SetEnvironmentVariable, on the other hand, makes a lasting change to
the current environment.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list