[Python] python-dotenv (.env)
- 2025.12.10
- Python
安裝1GitHub: python-dotenv
pip install python-dotenv
.env
ROOT=root
USER=${ROOT}
load_dotenv()
By default, load_dotenv() will:
- Look for a
.envfile in the same directory as the Python script (or higher up the directory tree). - Read each key-value pair and add it to
os.environ. - Not override an environment variable that is already set, unless you explicitly pass
override=True.
from dotenv import load_dotenv
load_dotenv()
import os
print(os.getenv('USER')) # root
Last Updated on 2025/12/10 by A1go