Python Module os

From NovaOrdis Knowledge Base
Revision as of 00:26, 22 July 2022 by Ovidiu (talk | contribs) (→‎Environment Variables)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

External

Internal

Overview

Environment Variables

To get an environment variable:

import os

print(os.environ.get('HOME'))

If the environment variable does not exist, the call will get None

To set an environment variable:

import os
os.environ['MY_VAR'] = 'myvalue'

This works for testing. It does not change the value of the corresponding environment variable, if it exists, or it does not set a new one, if it doesn't, in the environment that calls the python interpreter.

Working Directory

File Operations in Python | Working Directory