【发布时间】:2016-05-29 18:46:47
【问题描述】:
我正在尝试制作一个银行程序,您现在可以选择更改选项“2”中的密码。我尝试这样做但无济于事。谁能告诉我如何更改密码存储在“store.txt”的第 2 行。
示例:
这是我存储在文件“store.txt”中的数据
hello,me,0
bye,you,0
我要做的是将用户名“hello”的密码更改为“yolo”。我该怎么做?
这是我的代码:
import csv
run=True
while run==True:
print "1)Create a new account"
print "2) Change Password"
choice=input("Enter your choice over here: ")
#This part takes the input from the user and then stores it in 'store.txt'
if choice==1:
a=input("Enter how many people to register: ")
for i in range(0,a) :
#Stores username and password
a=raw_input("Enter username: ")
b=raw_input("Enter password: ")
c=0
#If username already exists, stop the process.
with open ('store.txt','r') as store:
reader = csv.reader(store)
for row in reader:
if a==row[0]:
print "User already exists in our database , please try again."
break
store.close()
#If username is not there , write it down to store.txt
with open ('store.txt','a') as store:
storeWriter=csv.writer(store)
storeWriter.writerow([a,b,c])
store.close()
if choice==2:
print "Change password"
【问题讨论】:
标签: python python-2.7 csv row