HOST=localhost
python-dotenv library
- Install
python-dotenv
library from the command line:
pip install python-dotenv
- Load environment variables from
.env
file:
import os
from os.path import dirname, abspath
from dotenv import load_dotenv
path = dirname(abspath(__file__)) + '/.env'
load_dotenv(path)
envVar = os.getenv('HOST')
print(envVar) # localhost
Leave a Comment
Cancel reply