@@ -109,8 +109,8 @@ process and user.
109
109
110
110
This mapping is captured the first time the :mod: `os ` module is imported,
111
111
typically during Python startup as part of processing :file: `site.py `. Changes
112
- to the environment made after this time are not reflected in `` os.environ ` `,
113
- except for changes made by modifying `` os.environ ` ` directly.
112
+ to the environment made after this time are not reflected in :data: ` os.environ `,
113
+ except for changes made by modifying :data: ` os.environ ` directly.
114
114
115
115
This mapping may be used to modify the environment as well as query the
116
116
environment. :func: `putenv ` will be called automatically when the mapping
@@ -122,8 +122,8 @@ process and user.
122
122
123
123
.. note ::
124
124
125
- Calling :func: `putenv ` directly does not change `` os.environ ` `, so it's better
126
- to modify `` os.environ ` `.
125
+ Calling :func: `putenv ` directly does not change :data: ` os.environ `, so it's better
126
+ to modify :data: ` os.environ `.
127
127
128
128
.. note ::
129
129
@@ -133,7 +133,7 @@ process and user.
133
133
134
134
You can delete items in this mapping to unset environment variables.
135
135
:func: `unsetenv ` will be called automatically when an item is deleted from
136
- `` os.environ ` `, and when one of the :meth: `pop ` or :meth: `clear ` methods is
136
+ :data: ` os.environ `, and when one of the :meth: `pop ` or :meth: `clear ` methods is
137
137
called.
138
138
139
139
.. versionchanged :: 3.9
@@ -224,7 +224,10 @@ process and user.
224
224
.. function :: getenv(key, default=None)
225
225
226
226
Return the value of the environment variable *key * if it exists, or
227
- *default * if it doesn't. *key *, *default * and the result are str.
227
+ *default * if it doesn't. *key *, *default * and the result are str. Note that
228
+ since :func: `getenv ` uses :data: `os.environ `, the mapping of :func: `getenv ` is
229
+ similarly also captured on import, and the function may not reflect
230
+ future environment changes.
228
231
229
232
On Unix, keys and values are decoded with :func: `sys.getfilesystemencoding `
230
233
and ``'surrogateescape' `` error handler. Use :func: `os.getenvb ` if you
@@ -236,7 +239,11 @@ process and user.
236
239
.. function :: getenvb(key, default=None)
237
240
238
241
Return the value of the environment variable *key * if it exists, or
239
- *default * if it doesn't. *key *, *default * and the result are bytes.
242
+ *default * if it doesn't. *key *, *default * and the result are bytes. Note that
243
+ since :func: `getenvb ` uses :data: `os.environb `, the mapping of :func: `getenvb ` is
244
+ similarly also captured on import, and the function may not reflect
245
+ future environment changes.
246
+
240
247
241
248
:func: `getenvb ` is only available if :data: `supports_bytes_environ `
242
249
is ``True ``.
@@ -443,10 +450,11 @@ process and user.
443
450
changes to the environment affect subprocesses started with :func: `os.system `,
444
451
:func: `popen ` or :func: `fork ` and :func: `execv `.
445
452
446
- Assignments to items in `` os.environ ` ` are automatically translated into
453
+ Assignments to items in :data: ` os.environ ` are automatically translated into
447
454
corresponding calls to :func: `putenv `; however, calls to :func: `putenv `
448
- don't update ``os.environ ``, so it is actually preferable to assign to items
449
- of ``os.environ ``.
455
+ don't update :data: `os.environ `, so it is actually preferable to assign to items
456
+ of :data: `os.environ `. This also applies to :func: `getenv ` and :func: `getenvb `, which
457
+ respectively use :data: `os.environ ` and :data: `os.environb ` in their implementations.
450
458
451
459
.. note ::
452
460
@@ -645,10 +653,10 @@ process and user.
645
653
environment affect subprocesses started with :func: `os.system `, :func: `popen ` or
646
654
:func: `fork ` and :func: `execv `.
647
655
648
- Deletion of items in `` os.environ ` ` is automatically translated into a
656
+ Deletion of items in :data: ` os.environ ` is automatically translated into a
649
657
corresponding call to :func: `unsetenv `; however, calls to :func: `unsetenv `
650
- don't update `` os.environ ` `, so it is actually preferable to delete items of
651
- `` os.environ ` `.
658
+ don't update :data: ` os.environ `, so it is actually preferable to delete items of
659
+ :data: ` os.environ `.
652
660
653
661
.. audit-event :: os.unsetenv key os.unsetenv
654
662
0 commit comments