I want to check my environment for the existence of a variable, say "FOO"
, in Python. For this purpose, I am using the os
standard library. After reading the library’s documentation, I have figured out 2 ways to achieve my goal:
Method 1:
if "FOO" in os.environ:
pass
Method 2:
if os.getenv("FOO") is not None:
pass
I would like to know which method, if either, is a good/preferred conditional and why.