|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
一个文件类容的改动
dict1={}
num=input("省份证件号:")
name=input("姓名:")
num2=input("房间号:")
num3=input("房费:")
num4=input("押金:")
A=open("信息表.text","a")
A.write(num+","+name+","+num2+","+num3+","+num4+","+"\n")
A.close()
B=open("信息表.text","r")
for eachline in B:
dict1[eachline[0:18]]=eachline[18:]
print(eachline[0:18])
print("1:查询住户信息 2:修改住户信息 3:添加住户 4:删除住户")
B.close()
Ch=input("请选择:")
if Ch==1:
Ch1=input("请输入身份证件号:")
print(dict1[Ch1])
elif Ch==2:
Ch1=input("请输入身份证件号:")
print(dict1[Ch1])
R=open("信息表.text","w")
dict[Ch1]=input("请按照顺序填写信息:")
for k,v in dict1:
R.write(k+","+v)
R.close()
elif Ch==3:
D=open("信息表.text","a")
num=input("省份证件号:")
name=input("姓名:")
num2=input("房间号:")
num3=input("房费:")
num4=input("押金:")
D.write(num+","+name+","+num2+","+num3+","+num4+","+"\n")
D.close()
else:
E=open("信息表.text","w")
Ch1=input("请输入身份证件号:")
dict1.pop(Ch1)
for k,v in dict1 :
E.write(k+","+v)
E.close()
显错
ValueError: too many values to unpack (expected 2)
试试这样: dict1={}
num=input("省份证件号:")
name=input("姓名:")
num2=input("房间号:")
num3=input("房费:")
num4=input("押金:")
A=open("信息表.text","a")
A.write(num+","+name+","+num2+","+num3+","+num4+","+"\n")
A.close()
B=open("信息表.text","r")
for eachline in B:
dict1[eachline[0:18]]=eachline[18:]
print(eachline[0:18])
print("1:查询住户信息 2:修改住户信息 3:添加住户 4:删除住户")
B.close()
Ch=input("请选择:")
if Ch==1:
Ch1=input("请输入身份证件号:")
print(dict1[Ch1])
elif Ch==2:
Ch1=input("请输入身份证件号:")
print(dict1[Ch1])
R=open("信息表.text","w")
dict[Ch1]=input("请按照顺序填写信息:")
for k,v in dict1.items():
R.write(k+","+v)
R.close()
elif Ch==3:
D=open("信息表.text","a")
num=input("省份证件号:")
name=input("姓名:")
num2=input("房间号:")
num3=input("房费:")
num4=input("押金:")
D.write(num+","+name+","+num2+","+num3+","+num4+","+"\n")
D.close()
else:
E=open("信息表.text","w")
Ch1=input("请输入身份证件号:")
dict1.pop(Ch1)
for k,v in dict1.items() :
E.write(k+","+v)
E.close()
|
|