$ pip install python-dotenv
.env檔 內容↓↓↓
IP=10.15.10.47 PORT=8080 USER_NAME="ADMIN" PASSWORD=P@ssw0rd
test_ditenv.py
import os from dotenv import load_dotenv load_dotenv()
IP = os.getenv('IP') PORT = os.getenv('PORT') USER_NAME = os.getenv('USER_NAME') PASSWORD = os.getenv('PASSWORD') print(f'IP => {IP} ', type(IP)) print(f'PORT => {PORT} ', type(PORT)) print(f'USER_NAME => {USER_NAME} ', type(USER_NAME)) print(f'PASSWORD => {PASSWORD} ', type(PASSWORD))IP => 10.15.10.47 <class 'str'>
PORT => 8080 <class 'str'>
USER_NAME => ADMIN <class 'str'>
PASSWORD => P@ssw0rd <class 'str'>
沒有留言:
張貼留言