Gregory P. Smith added the comment:
>>> os.environ['FOO']
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: 'FOO'
>>> os.environ.get('FOO')
>>> os.environ.get('FOO', 'bar')
'bar'
% export
New submission from Mary Stern :
os.environ.get('ENV_VAR, 'mydefault')
returns '' rather than 'mydefault' if not set.
It would be nice if this standard dict-style behavior was supported.
--
messages: 81963
nosy: marystern
severity: normal
status: open
title: os.environ.get() doesn't ha