I am trying to read through some source code and found this. Someone tell me what the second parameter "29" does? I am used to only seeing one parameter
OWNER_ID = os.environ.get("OWNER_ID", "29")
I am trying to read through some source code and found this. Someone tell me what the second parameter "29" does? I am used to only seeing one parameter
OWNER_ID = os.environ.get("OWNER_ID", "29")
Because os.environ
returns a dedicated mapping type (and not a dictionary as user2357112 has pointed out in the comment) that inherits the get()
method from the Mapping
class, it works similarly to dict.get()
. So the following line:
OWNER_ID = os.environ.get("OWNER_ID", "29")
would be equivalent to
try:
OWNER_ID = os.environ["OWNER_ID"]
except KeyError:
OWNER_ID = "29"
It implicitly handles the KeyError
and returns the default value "29"
instead of raising an error if the key "OWNER_ID"
does not exist.
See also: