Primary
os.environ ⚬|Documentation|1st|20260605005430-00-⌔
os — Miscellaneous operating system interfaces — Python 3.14.5 documentation#os.environ
os.environA mapping object where keys and values are strings that represent the process environment. For example,
environ['HOME']is the pathname of your home directory (on some platforms), and is equivalent togetenv("HOME")in C.This mapping is captured the first time the
osmodule is imported, typically during Python startup as part of processingsite.py. Changes to the environment made after this time are not reflected inos.environ, except for changes made by modifyingos.environdirectly.This mapping may be used to modify the environment as well as query the environment.
putenv()will be called automatically when the mapping is modified.On Unix, keys and values use
sys.getfilesystemencoding()and'surrogateescape'error handler. Useenvironbif you would like to use a different encoding.On Windows, the keys are converted to uppercase. This also applies when getting, setting, or deleting an item. For example,
environ['monty'] = 'python'maps the key'MONTY'to the value'python'.Note: Calling
putenv()directly does not changeos.environ, so it’s better to modifyos.environ.Note: On some platforms, including FreeBSD and macOS, setting
environmay cause memory leaks. Refer to the system documentation forputenv().You can delete items in this mapping to unset environment variables.
unsetenv()will be called automatically when an item is deleted fromos.environ, and when one of thepop()orclear()methods is called.See also: The
os.reload_environ()function.Changed in version 3.9: Updated to support PEP 584 ’s merge (
|) and update (|=) operators.Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •