小弟初学 python ,最新在练习做一个密码验证测试程序
username_f = open('username.txt')
login_f = open('login.txt')
for i in range(3):
username = raw_input('username:').strip()
password = raw_input('password:').strip()
if len(username) != 0 and len(password) != 0:
f = open(username_f)
for line in f.readlines():
if username == line.split()[0] and password == line.split()[1]:
#判断输入的用户名与密码是否在 line 这个列别当中
print "Welcome %s login my system " % username
break
break
else:
continue
username:test
password:test
Traceback (most recent call last):
File "C:\Users\lenvovx201i\Desktop\python\zuoye1.py", line 10, in <module>
f = open(username_f)
TypeError: coercing to Unicode: need string or buffer, file found
请按任意键继续. . .
各位老手请帮忙看看是什么问题
1
yongzhong 2015-12-08 13:20:32 +08:00
username_f = open('username.txt')已经打开一次了
而在下面又 f = open(username_f) 问题很明显呀.... |
3
RickyBoy 2015-12-08 17:17:05 +08:00
f = open(open('username.txt'))
|