zoukankan      html  css  js  c++  java
  • 作业3月16号

    1、通用文件copy工具实现

    src_fire = input('复制路径》')
    dsc_fire = input('粘贴路径》')
    with open(r'{}'.format(src_fire),mode='rb')as f1,
        open(r'{}'.format(dsc_fire),mode='wb')as f2:
        for msg in f1:
            f2.write(msg)

    2、基于seek控制指针移动,测试r+、w+、a+模式下的读写内容

    # r+t  模式
    with open(r'C:UsersAdministratorDesktopa.txt',mode='r+',encoding='utf-8')as f:
        f.seek(2,0)
        print(f.read())
    # r+b   模式
    with open(r'C:UsersAdministratorDesktopa.txt',mode='r+b',)as f1:
        f1.seek(2,0)
        print(f1.read().decode('utf-8'))
    # w+b   模式
    with open(r'a.txt', mode='w+b', )as f2:
        f2.write(b'lsd123')
        f2.seek(2,0)
        print(f2.read())
        f2.write(bytes('',encoding='utf-8'))
        f2.seek(4,0)
        print(f2.read().decode('utf-8'))
    # a+b 模式
    
    with open(r'a.txt', mode='a+b', )as f3:
        f3.write(b'lsd123')
        f3.seek(3, 0)
        print(f3.read().decode('utf-8'))
        f3.write(bytes('上xia', encoding='utf-8'))
        f3.seek(5, 0)
        print(f3.read().decode('utf-8'))

    3、tail -f access.log程序实现

    import time
    with open('access.log', 'rt', encoding='utf-8') as f:
        f.seek(0, 2)
        while True:
            res = f.readline()
            if not res:
                time.sleep(0.5)
                continue
            print(res)

    4、周末作业参考在老师讲解完毕后(下午17:30开始讲解),练习熟练,明早日考就靠他俩

     4.1:编写用户登录接口

    tag = True
    while tag:
        username = input('请输入用户名: ').strip()
        with open('user_info4.txt', 'r', encoding='utf-8') as f, open('user_info5.txt', 'w', encoding='utf-8') as w:
            for line in f:
                user, pwd, locked = line.strip().split(':')
                # print(user, pwd, type(locked))
                locked = int(locked)
    
                if locked == 3:
                    print('当前用户已被锁定')
    
                if username == user:
                    while locked < 3:
                        password = input('请输入密码: ').strip()
                        if password == pwd:
                            print('登录成功!')
                            tag = False
                            break
                        else:
                            print('密码错误!')
                            locked += 1
    
                w.write(f'{user}:{pwd}:{locked}
    ')
    
        import os
        os.remove('user_info4.txt')
        # 将user_info5.txt修改为user_info4.txt
        os.rename('user_info5.txt', 'user_info4.txt')


     4.2:编写程序实现用户注册后(注册到文件中),可以登录(登录信息来自于文件)

    while True:
        msg = """
        0 退出
        1 登录
        2 注册
        """
        print(msg)
        cmd = input('请输入命令编号>>: ').strip()
        if not cmd.isdigit():
            print('必须输入命令编号的数字,傻叉')
            continue
    
        if cmd not in dic:
            print('输入有误')
            continue
    
        print(dic.get(cmd))
  • 相关阅读:
    C#知识点总结系列:5、CLR的组成和运转
    SQL知识整理三:变量、全局变量、视图、事务、异常
    SQL知识整理二:锁、游标、索引
    SQL知识整理一:触发器、存储过程、表变量、临时表
    TFS二次开发系列:六、TFS的版本控制
    TFS二次开发系列:五、工作项查询
    TFS二次开发系列:四、TFS二次开发WorkItem添加和修改、保存
    TFS二次开发系列:三、TFS二次开发的第一个实例
    TFS二次开发系列:二、TFS的安装
    TFS二次开发系列:一、TFS体系结构和概念
  • 原文地址:https://www.cnblogs.com/jingpeng/p/12506820.html
Copyright © 2011-2022 走看看