Python Module os: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 7: Line 7:


=Environment Variables=
=Environment Variables=
To get an environment variable:


<syntaxhighlight lang='python'>
<syntaxhighlight lang='python'>
Line 15: Line 17:


If the environment variable does not exist, the call will get <code>[[Python_Language#None|None]]</code>
If the environment variable does not exist, the call will get <code>[[Python_Language#None|None]]</code>
To set an environment variable:
<syntaxhighlight lang='python'>
import os
os.environ['MY_VAR'] = 'myvalue'
</syntaxhighlight>
If the environment variable does not exist, the call will get <code>[[Python_Language#None|None]]</code>
=Working Directory=
=Working Directory=
{{Internal|File_Operations_in_Python#Working_Directory|File Operations in Python &#124; Working Directory}}
{{Internal|File_Operations_in_Python#Working_Directory|File Operations in Python &#124; Working Directory}}

Revision as of 04:26, 17 February 2022

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'

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

Working Directory

File Operations in Python | Working Directory