python隐藏数据库密码忘了怎么办_如何在数据库连接中隐藏密码?

您可以创建一个函数来读取登录信息:#

# This function gets the login information out of a credentials file

#

def get_login_info(file):

# Create an array of the lines of the file

line = open(file, "r").readlines()

# Create a new list to be used to append the cleaned / trimmed lines

new_line = []

# Loop through the file

for a in line:

# Get rid of any new lines ("enter")

a = a.replace("\n", "")

# Add the cleaned data to the new_line list

new_line.append(a)

# Set the username to be the first object

username = new_line[0]

# Set the password to be the second object

password = new_line[1]

# Return them

return username, password

然后,使用它并将其传递给连接字符串:

^{pr2}$

因此示例文件可以是

:JerryM

Mypassword2019

它将JerryM存储为username,而{}则存储为password

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值