why os.environ dictionary remembers previously set variables??

ed_tsang at yahoo.com ed_tsang at yahoo.com
Fri May 11 14:11:38 EDT 2001

Hi I use the code 
print os.environ['THARN']
print os.environ['CTF']
if os.environ.has_key('THARN') and os.environ.has_key('CTF'):
    print "\nEither THARN or CTF shall be set not BOTH"
    print "before starting the Test Harness."
elif os.environ.has_key('THARN'):
    tharn = os.environ['THARN']
    print 'THARN'
elif os.environ.has_key('CTF'):
    tharn = os.environ['THARN']
    print 'CTF'
    print "\nEnvironment variable THARN must be set"
    print "before starting the Test Harness."
to do wset a local global thanr variable. 

In the .cshrc file in my home directory , I had:
setenv THARN /vobs/qa/stf/ctf/src/ctf 
set in the first run of my script.
It prints the correct content of tharn.
Then I exit the process, unset tne variable using
unsetenv THARN
setenv CTF /vobs/qa/stf/ctf/src/ctf
and uses echo to make sure THARN is gone while CTF is set.
Then I run the script again.. t my dismay, it prints both CTF and 
THARN having the value:


Either THARN or CTF shall be set not BOTH
before starting the Test Harness.
 I then go to delete the .pyc file and run it again same thing 
I use echo again and the system shows THRAN is gone while CTF is here 
which is expected... then why the heck python remembers the the alst 
one and just append the new environment variable???

What to do?? should I expliciltly delete all the variables in 
os.environ dict before exiting.. As you know it depends on user to 
set CTF ,THRAN , BOTH (error) or none at all (error). The latter use 
are error cases.


More information about the Python-list mailing list