1. 程式人生 > >python文件讀取操作

python文件讀取操作

bre cnblogs data col str () name clas txt

 1 #IO操作
 2 #模擬賬號登錄
 3 
 4 data = [] #0=userName 1=password
 5 
 6 obj = open("login.txt","r")
 7 for line in obj:
 8     data.append(line.strip("\n"))
 9 obj.close()
10 
11 
12 while True:
13     print("---------")
14     print("| 登錄 |")
15     print("---------")
16     userName = input("input your userName: 
") 17 if(userName == data[0]): 18 password = input("input your password: ") 19 if(password == data[1]): 20 print("登錄成功") 21 break 22 else: 23 print("密碼錯誤") 24 else: 25 print("賬號錯誤")

python文件讀取操作