Trying to load environment varibles in python module
import os
class Config(object):
port = os.environ.get("PORT") or 5000
print(Config.port)
$ 5000
Trying to load environment varibles in python module
import os
class Config(object):
port = os.environ.get("PORT") or 5000
print(Config.port)
$ 5000
pip
or pipenv
i.e virtualenv env
source env/bin/acivate
python-dotenv
module pip install python-dotenv
On top of your python file have something like this
In my .env
file I have a variable named MY_VARIABLE
MY_VARIABLE=Somevalue
app.py
I have thisimport os
from dotenv import load_dotenv
# Loading up the values
load_dotenv()
class Config(object):
port = os.environ.get("MY_VARIABLE") or 5000
print(Config.port)
$ Somevalue