Help setting CGI Environment Variables

Roman Suzi rnd at onego.ru
Sat May 26 23:51:11 EDT 2001


On Sat, 26 May 2001, Ari David Greenberg wrote:

>I am trying to write a CGI script that must modify some CGI environment
>variables. How should I do this? I tried the following:
>
>#!/usr/pubsw/bin/python
>import sys, os
>os.putenv("TEST_VAR", "/abc")
>
>for name, value in os.environ.items():
>	print "%s\t= %s" % (name, value)

#!/usr/bin/python
import sys, os
os.environ["TEST_VAR"] = "/abc"
for name, value in os.environ.items():
        print "%s\t= %s" % (name, value)

gives you this result.

*

However, I'd liked to do it this way:

exec """
TEST_VAR1 = "/abc"
TEST_VAR2 = "/abc"
""" in os.environ.data

for name, value in os.environ.items():
        print "%s\t= %s" % (name, value)


- but it remains unclear if this is legal. (os.environ is
an object).

>
>
>I ran this program from the command prompt, and it printed all my
>environment variables however it did not print TEST_VAR. I am concerned
>that I am not setting TEST_VAR properly. I thought os.putenv(<name>,
><value>) was the way to do it, but I'm having difficulties.
>
>Any help greatly appreciated. Please email me.
>
>-Ari
>
>

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Sunday, May 27, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Hard work must have killed someone!" _/





More information about the Python-list mailing list