文件内容
admin,111111
张三,222222
李四,333333
网上搜的资料,再根据读取成list的改了改,代码如下
blist = {}
f = open('b.txt')
for line in f:
line = line.strip().split(',')
blist[line[0]] = line[1]
print(blist)
f.close()
但是,中文读不出来,又加上了“, encoding='utf-8'
”,就可以显示中文了,奇怪度list时候为啥没事
f = open('b.txt', encoding='utf-8'
)
将输入的内容存入字典
blist = {}
f = open('b.txt', encoding='utf-8')
for line in f:
line = line.strip().split(',')
blist[line[0]] = line[1]
print(blist)
f.close()
username = input('请输入姓名:')
passwd = input('请输入密码:')
blist[username]=passwd
print(blist)
# print(','.jo