1.编写文件copy工具
1 src_file = input(">>>请输入要拷贝的文件路径:").strip()
2 copy_file = input(">>>请输入拷贝文件的存放位置:").strip()
3 with open(r'{}'.format(src_file), 'rt', encoding='utf-8') as f,\
4 open(r'{}\copy.txt'.format(copy_file), 'wt', encoding='utf-8') as copy_f:
5 copy = f.read()
6 copy_f.write(copy)
2、编写登录程序,账号密码来自于文件
1 print("登录")
2 inp_user = input(">>>your name:").strip()
3 inp_pwd = input(">>>your password:").strip()
4 with open(r'user.txt', 'rt', encoding='utf-8') as f:
5 for line in f:
6 user, pwd = line.strip().split(':')
7 if user == inp_user and pwd == inp_pwd:
8 print('login success')
9 break
10 else:
11 print('用户名或密码错误')
3、编写注册程序,账号密码来存入文件
1 print("注册")
2 inp_user = input(">>>your name:").strip()
3 inp_pwd = input(">>>your password:").strip()
4 with open(r'user.txt', 'at', encoding='utf-8') as f:
5 f.write('{user}:{pwd}\n'.format(user=inp_user, pwd=inp_pwd))