1、编写文件copy工具
original_path = input('请输入源文件的路径>>>').strip()
copy_path = input('请输入拷贝文件的路径>>>').strip()
with open(r'{}'.format(original_path),mode = 'rt',encoding = 'utf-8') as f1,
open(r'{}'.format(copy_path),mode = 'wt',encoding = 'utf-8') as f2:
content = f1.read()
f2.write(content)
2、编写登录程序,账号密码来自于文件
inp_name = input('请输入你的账号:').strip()
inp_pwd = input('请输入你的密码:').strip()
with open(r'aaa.txt',mode = 'rt',encoding = 'utf-8') as f:
for line in f:
user_name,password = line.strip().split(':')
if inp_name == user_name and inp_pwd == password:
print('登录成功。')
break
else:
print('账号或密码错误。')
3、编写注册程序,账号密码来存入文件
inp_name = input('请输入账号:').strip()
inp_pwd = input('请输入密码:').strip()
with open(r'db.txt',mode = 'at',encoding = 'utf-8') as f:
f.write('{}:{}
'.format(inp_name,inp_pwd))