python - 为什么这会打印 Invalid Credentials 而不是 Logged In
问题描述
我正在学习 Python。我有这个代码:
import csv
# Asking for user Inputs
user_name = input('Enter Username: ')
password = input('Enter Password: ')
def login(user_name, password):
# Opening the CSV File
with open('user_info.csv', 'r') as user_info_file:
# Defining the file reader
csv_reader = csv.reader(user_info_file)
# Checking if the user credentials are correct
for user in csv_reader:
# Checking if the user_name and password are in the csv file
if user[0] == user_name and user[1] == password:
return True
return False
authenticate = login(user_name, password)
if authenticate == True:
print('Logged In')
else:
print("Wrong Credentials")
当我输入与 csv 文件中相同的用户名和密码时,它正在打印Invalid Credentials
而不是Logged in
.
有人可以帮忙吗?
解决方案
推荐阅读
- scala - 如何获取在 GROUP BY 子句中分组的元素的 Seq?
- reactjs - 在 react-native 中用 createStructuredSelector 替换 useSelector
- java - Eclipse:使用 Coverage 进行测试会抛出 java.lang.instrument.IllegalClassFormatException
- ios - Swift右栏按钮项目填充问题?
- karate - 是否可以使用命令行覆盖在 Runner.path() 中声明的类路径?
- android - 如何触发深度链接?
- python - pygame游戏中的高分
- java - 为什么我在 findViewbyID 上收到错误消息?
- r - 是否可以在 ggplot2 的单个时间序列图中绘制多条趋势线?
- java - java android retrofit2 - 如何访问 JSON 响应对象