擅长:python、mysql、java
<p>一种选择是使用<a href="https://pypi.org/project/python-dotenv/" rel="nofollow noreferrer">dotenv</a></p>
<p>这样,您可以将您的私人详细信息保存在一个名为<code>.env</code>的单独文件中</p>
<p>然后在运行时读取脚本中的私有详细信息</p>
<p>例如:</p>
<p>File.env值:</p>
<pre><code>USERNAME=MyUserName
PASSWORD=Spec!alP@ssw0rd*19?
</code></pre>
<p>脚本使用:</p>
<pre><code>import os # also need os
from dotenv import load_dotenv
load_dotenv() # blank if .env file in same directory as script
# load_dotenv('<path to file>.env') to point to another location
USERNAME = os.getenv('USERNAME')
PASSWORD = os.getenv('PASSWORD')
# your code
</code></pre>