zoukankan      html  css  js  c++  java
  • python学习之文件基本处理作业

    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))
    
  • 相关阅读:
    php odbc连接 查询显示不完整问题
    php集成环境
    intent实现网页跳转
    夜神模拟器
    Android编程知识点3-Intent
    Android编程知识点2- 线性布局,随机数
    Android编程知识点1-Button,ListView
    数据存储和访问
    Android计时器
    组件通信2
  • 原文地址:https://www.cnblogs.com/leilijian/p/12488504.html
Copyright © 2011-2022 走看看