by
0
6
2,428
0
Top 1% !
Popular
Famous
Tagged
Specified
OpenSource
Popularity: 7972nd place
Created
Modified Apr 10, 2013

Published on:

Languagepython
LicenseMIT_X11

Get environment variable value in python

This python method gets the value of a specific environment variable. If variable doesn't exist a default value is returned.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/730/Get-environment-variable-value-in-python?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
#!/usr/bin/python import os # Get environment def getenv(name, default=''): try: # get "$x" environment var return os.environ[name] except KeyError: return default
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus