From my ipython shell, I see a method setdefault in os.environ but it is not documented. http://docs.python.org/library/os.html#os.environ. Is it documented somewhere else?
def setdefault(self, key, failobj=None):
if key not in self:
self[key] = failobj
return self[key]
Can I use this function or write a wrapper for those lines?
The
os.environdocumentation does state it’s a mapping:As such it behaves according to the python mapping documentation of which
dictis the standard implementation.os.environtherefor behaves just like the standard dict, it has all the same methods:The
.setdefaultmethod is documented on the same page as the rest of the mapping methods, and you can use it just fine as is.