1、编写文件copy工具
path_file = input('请输入想要复制文件的绝对路径:').strip()
path_file2 = input('请输入想要复制文件到哪里的绝对路径:').strip()
with open(r'file'.format(file=path_file), mode='rt', encoding='utf - 8') as f1,
open(r'file2'.format(file2=path_file2), mode='wt', encoding='utf - 8') as f2:
res = f1.read()
f2.write(res)
2、编写登录程序,账号密码来自于文件
username = input('请输入您的账号:').strip()
password = input('请输入您的密码:').strip()
with open('db.txt', mode='rt', encoding='utf-8') as f:
for i in f:
user_name, user_pwd = i.strip().split(':')
if username == user_pwd and password == user_pwd:
print('登陆成功')
break
else:
print('登陆失败')
3、编写注册程序,账号密码来存入文件
username = input('请输入您的账号:').strip()
password = input('请输入您的密码:').strip()
with open('db.txt', mode='at', encoding='utf-8') as f:
f.write('{x}:{y}'.format(x=username, y=password))