python .env change saves



我正在制作一个用户名和密码python的东西,我想知道如何让我的。env保存其内容。请将编辑的代码放在评论中,并描述您更改的内容。谢谢!

代码:

import os
os.environ['USER'] = 'admin'
os.environ['PASSWORD'] = 'admin'
print('Please Log In. admin Is The Defalt User And Password')
print('Username:')
inputed_username = input()
logged_username = os.getenv('USER')
if  inputed_username == logged_username :
logged_password = os.environ.get('PASSWORD')
print('Password:')
inputed_password = input()
if inputed_password == logged_password :
print('Welcome ' + inputed_username + '!')
while True :
print('What Do You Want To Do?')
print('''
1: Change Username
2: Change Password
3: Log Out
''')
ch1 = input()
if ch1 == '1' :
print('What Do You Want Your New Username To Be?')
new_username = input()
os.environ['USER'] = new_username

if ch1 == '2' :
print('What Do You Want Your New Password To Be?')
new_password = input()
os.environ['PASSWORD'] = new_password

if ch1 == "3" :
break


else :
print('WRONG PASSWORD')
else :
print('WRONG USERNAME')

我正在制作一个用户名和密码python的东西,我想知道我将如何保存我的。env的内容

modifyos.environ。看到这里。

inputed_username = input()
os.environ['USER_NAME'] = inputed_username 

读取env

value = os.getenv('USER_NAME','admin')  # admin is the default

相关内容

  • 没有找到相关文章

最新更新