Logo

Programming-Idioms

History of Idiom 205 > diff from v15 to v16

Edit summary for version 16 by programming-idioms.org:
[Python] Avoid underscores in snippets

Version 15

2019-09-30, 19:09:21

Version 16

2019-10-01, 08:32:40

Idiom #205 Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

Idiom #205 Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

Extra Keywords
envvar os system
Extra Keywords
envvar os system
Imports
import os
Imports
import os
Code
try:
    _foo = os.environ['FOO']
except KeyError:
    _foo = None
Code
try:
    foo = os.environ['FOO']
except KeyError:
    foo = None
Doc URL
https://docs.python.org/3/library/os.html
Doc URL
https://docs.python.org/3/library/os.html