Skip to content

Instantly share code, notes, and snippets.

@dmwyatt
Created December 25, 2021 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmwyatt/d898f5fc203ee56e24e6dbe826b07d6e to your computer and use it in GitHub Desktop.
Save dmwyatt/d898f5fc203ee56e24e6dbe826b07d6e to your computer and use it in GitHub Desktop.
[read dot env] Read a .env file and set the env vars
with suppress(FileNotFoundError):
with open('.env') as f:
line = f.readline()
while line:
k, v = line.split('=', 1)
os.environ[k] = v.strip()
line = f.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment