반응형
What is the correct way to unset a linux environment variable in python?
From the documentation:
If the platform supports the
unsetenv()function, you can delete items in this mapping to unset environment variables.unsetenv()will be called automatically when an item is deleted from os.environ, and when one of thepop()orclear()methods is called.
However I want something that will work regardless of the availability of unsetenv(). How do I delete items from the mapping if it's not available? os.environ['MYVAR'] = None?
Just
del os.environ['MYVAR']
should work.
You can still delete items from the mapping, but it will not really delete the variable from the environment if unsetenv() is not available.
del os.environ['MYVAR']
ReferenceURL : https://stackoverflow.com/questions/3575165/what-is-the-correct-way-to-unset-a-linux-environment-variable-in-python
반응형
'Program Club' 카테고리의 다른 글
| What does deployment target mean? (0) | 2020.12.25 |
|---|---|
| FULL OUTER JOIN with SQLite (0) | 2020.12.25 |
| python class that acts as mapping for **unpacking (0) | 2020.12.25 |
| Why am I getting AttributeError: Object has no attribute (0) | 2020.12.25 |
| Preprocessor check if multiple defines are not defined (0) | 2020.12.25 |