Hello , I'm yuechuang .
Blog launch :https://bornforthis.cn/posts/19.html
Sometimes you need to store sensitive information in your code , For example, password or API secret key , And in the Python The simplest way to do this is to use os and dotenv modular .
So , You need to install dotenv modular , and os Module is standard Python modular , No installation required .
On the command line , Input :
pip install python-dotenv
Or for Python 3
pip3 install python-dotenv
hypothesis .env
The contents of the file are :
API_KEY="abcd123"
A good practice is to include a in your project .env
file , It contains examples of each secret variable you are using . The contents of this document are as follows :
API_KEY="abcd123"
To load it into your python In file , You should :
import os
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv("API_KEY")
Good! Now? , You are hiding data correctly !
Yuechuang · Programming one-to-one AI Yuechuang · Launch the tutorial class , Include 「Python Language tutoring class 、C++ The tutorial class 、java The tutorial class 、 Algorithm / Data structure tutorial class 、 Children programming 、pygame Game development 」, It's all one-on-one teaching : One on one coaching + One on one + Homework assignment + Project practice, etc . Of course , Also take photography courses offline 、Photoshop、Premiere One on one teaching 、QQ、 Wechat Online , Be ready to respond ! WeChat :JiabcdefhC++ Information Olympiad solution , Long term renewal ! Long term recruitment of one-to-one primary and secondary school information Olympiad training , Putian 、 Xiamen has the opportunity to visit offline , Other regional online . WeChat :Jiabcdefh
Catalog python Calculate the a