[issue5253] os.environ.get() doesn't handle default value

Gregory P. Smith report at bugs.python.org
Fri Feb 13 20:21:54 CET 2009


Gregory P. Smith <greg at krypto.org> added the comment:

>>> os.environ['FOO']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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 FOO=
% python2.5
>>> import os
>>> os.environ['FOO']
''

An environment variable set to '' is valid and is still considered set
(thats how the environment works).

----------
nosy: +gregory.p.smith
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5253>
_______________________________________


More information about the Python-bugs-list mailing list