How to clear os.environ value for only one variable in Python

I install os.environ['PYTHONHOME']="/home/user/OpenPrint/py2.6" in my python script

But at the end of the script, I need to clear this variable so that I can call another python script from another place. Can someone tell me how to do this? I tried os.environ.clear() , but this also clears all other variables.

+4
source share
3 answers

Using

 os.environ.pop("PYTHONHOME") 

See the (minimal) documentation at http://docs.python.org/2/library/os.html

+4
source

try

 del os.environ["PYTHONHOME"] 

this variable removes "PYTHONHOME" from the os.environ dict.

+3
source
 os.unsetenv('PYTHONHOME') 

This will disable the environment variable.

0
source

Source: https://habr.com/ru/post/1496472/


All Articles