Guest User

Untitled

a guest
Aug 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. import os
  2.  
  3. ...
  4.  
  5. # if the key doesn't exist than raise a 'KeyError'
  6. my_url = os.environ['my_variable_name']
  7.  
  8. # using get will return 'None' if a key is not present rather than raise a 'KeyError'
  9. my_url = os.environ.get('KEY_THAT_MIGHT_EXIST')
  10.  
  11. # os.getenv is equivalent, and can also give a default value instead of 'None'
  12. my_url = os.getenv('KEY_THAT_MIGHT_EXIST', default_value)
  13.  
  14. ...
Add Comment
Please, Sign In to add comment