Values from outside of your application
Connecting to a database
Determining the operating system
Setting which need to change
Sensitive data
Reading an environmentaal variable
import os os_version = os.getenv('OS') print(os_version)
Using dotenv
Store environmental variables in text file
# .env file DATAbase = Sample_Connection_string #app.py from dotenv import load_dotenv import os load_dotenv() database = os.getenv('DATAbase') print(database)
PS: 用 dotenv 就不用在各个文件中引入配置文件,保护敏感信息,利于后期代码维护。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)