Difference between os.getenv and os.environ.get?
Is there any difference at all between these two? When should I use one over the other? Is one of these deprecated? They seem to have the exact same functionality.
>>> os.getenv('TERM') 'xterm' >>> os.environ.get('TERM') 'xterm' >>> os.getenv('FOOBAR', "not found") == "not found" True >>> os.environ.get('FOOBAR', "not found") == "not found" True
One difference observed (Python27):
os.environ raises an exception if the environmental variable does not exist.
os.getenv does not raise an exception, but returns None
★ Back to homepage or read more recommendations: