newbie: Windows os.getenv(...

Diez B. Roggisch nospam-deets at web.de
Mon Oct 20 04:57:26 EDT 2003


Hi,

> i´d like to use environment variables within an python script.
> I can read with
>>>>t1 = os.getenv("temp")
> but not
>>>>d1 = os.getenv("%date%")

%<name>% means that the command.com (or whatever its called under >w2k) is
supposed to substitute the expression with the value of the variable
<name>. E.g:

set PATH=bar
set PATH=%PATH%;foo
echo %PATH%
->bar;foo

However, in python-scripts the command.com isn't going to replace anything,
as its not running your script.

> Also I cannot change environment variables with
> os.putenv("any" , "something")

I have very limited windows expirience, but under unix a child process
(thats what your python-interpreter is) inherits the environment of its
parent by getting an actual copy. Otherwise it wouldn't be possible to
alter env-variables while other child-processes are running without
affecting these. So you can't overwrite the env of your parent process.

Maybe there is a way, but I have to admit I don't know how.

Regards,

Diez




More information about the Python-list mailing list