Answers for "using dotenv_values"

0

using dotenv_values

from dotenv import dotenv_values

# This function does not touch the os's environment rather it parses the .env file and returns a dict object
# containing parsed values

################################################################################################
# Example .env file
'''
# .env file
USER=foo
SECRET_KEY=v%)9n7kg^65(4-uir6!pa@oqqsdn8agv9h8_#ohn*55$th-gff
DOMAIN=tester.org
EMAIL=admin@${DOMAIN}
'''
################################################################################################

#Loading .env file values to config variable

config = dotenv_values(".env")

# above load is similar to executing the following in python
#config = {"USER":"foo","SECRET_KEY":"v%)9n7kg^65(4-uir6!pa@oqqsdn8agv9h8_#ohn*55$th-gff","EMAIL": "[email protected]"}

#therfore accessing values we query the keys

print(config.get("DOMAIN"))
#OUTPUT : [email protected]
Posted by: Guest on September-15-2021

Browse Popular Code Answers by Language