@@ -177,8 +177,8 @@ process and user.
177
177
178
178
This mapping is captured the first time the :mod: `os ` module is imported,
179
179
typically during Python startup as part of processing :file: `site.py `. Changes
180
- to the environment made after this time are not reflected in `` os.environ ` `,
181
- except for changes made by modifying `` os.environ ` ` directly.
180
+ to the environment made after this time are not reflected in :data: ` os.environ `,
181
+ except for changes made by modifying :data: ` os.environ ` directly.
182
182
183
183
This mapping may be used to modify the environment as well as query the
184
184
environment. :func: `putenv ` will be called automatically when the mapping
@@ -190,8 +190,8 @@ process and user.
190
190
191
191
.. note ::
192
192
193
- Calling :func: `putenv ` directly does not change `` os.environ ` `, so it's better
194
- to modify `` os.environ ` `.
193
+ Calling :func: `putenv ` directly does not change :data: ` os.environ `, so it's better
194
+ to modify :data: ` os.environ `.
195
195
196
196
.. note ::
197
197
@@ -201,7 +201,7 @@ process and user.
201
201
202
202
You can delete items in this mapping to unset environment variables.
203
203
:func: `unsetenv ` will be called automatically when an item is deleted from
204
- `` os.environ ` `, and when one of the :meth: `pop ` or :meth: `clear ` methods is
204
+ :data: ` os.environ `, and when one of the :meth: `pop ` or :meth: `clear ` methods is
205
205
called.
206
206
207
207
.. versionchanged :: 3.9
@@ -292,7 +292,10 @@ process and user.
292
292
.. function :: getenv(key, default=None)
293
293
294
294
Return the value of the environment variable *key * if it exists, or
295
- *default * if it doesn't. *key *, *default * and the result are str.
295
+ *default * if it doesn't. *key *, *default * and the result are str. Note that
296
+ since :func: `getenv ` uses :data: `os.environ `, the mapping of :func: `getenv ` is
297
+ similarly also captured on import, and the function may not reflect
298
+ future environment changes.
296
299
297
300
On Unix, keys and values are decoded with :func: `sys.getfilesystemencoding `
298
301
and ``'surrogateescape' `` error handler. Use :func: `os.getenvb ` if you
@@ -304,7 +307,11 @@ process and user.
304
307
.. function :: getenvb(key, default=None)
305
308
306
309
Return the value of the environment variable *key * if it exists, or
307
- *default * if it doesn't. *key *, *default * and the result are bytes.
310
+ *default * if it doesn't. *key *, *default * and the result are bytes. Note that
311
+ since :func: `getenvb ` uses :data: `os.environb `, the mapping of :func: `getenvb ` is
312
+ similarly also captured on import, and the function may not reflect
313
+ future environment changes.
314
+
308
315
309
316
:func: `getenvb ` is only available if :data: `supports_bytes_environ `
310
317
is ``True ``.
@@ -511,10 +518,11 @@ process and user.
511
518
changes to the environment affect subprocesses started with :func: `os.system `,
512
519
:func: `popen ` or :func: `fork ` and :func: `execv `.
513
520
514
- Assignments to items in `` os.environ ` ` are automatically translated into
521
+ Assignments to items in :data: ` os.environ ` are automatically translated into
515
522
corresponding calls to :func: `putenv `; however, calls to :func: `putenv `
516
- don't update ``os.environ ``, so it is actually preferable to assign to items
517
- of ``os.environ ``.
523
+ don't update :data: `os.environ `, so it is actually preferable to assign to items
524
+ of :data: `os.environ `. This also applies to :func: `getenv ` and :func: `getenvb `, which
525
+ respectively use :data: `os.environ ` and :data: `os.environb ` in their implementations.
518
526
519
527
.. note ::
520
528
@@ -713,10 +721,10 @@ process and user.
713
721
environment affect subprocesses started with :func: `os.system `, :func: `popen ` or
714
722
:func: `fork ` and :func: `execv `.
715
723
716
- Deletion of items in `` os.environ ` ` is automatically translated into a
724
+ Deletion of items in :data: ` os.environ ` is automatically translated into a
717
725
corresponding call to :func: `unsetenv `; however, calls to :func: `unsetenv `
718
- don't update `` os.environ ` `, so it is actually preferable to delete items of
719
- `` os.environ ` `.
726
+ don't update :data: ` os.environ `, so it is actually preferable to delete items of
727
+ :data: ` os.environ `.
720
728
721
729
.. audit-event :: os.unsetenv key os.unsetenv
722
730
0 commit comments