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

    1、通用文件copy工具实现

    with open('users.txt','rb') as f1,open('users1','wb') as f2:
        for i in f1:
            f2.write(i)
    

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

    with open('users.txt','r+',encoding='utf-8') as f1:
        print(f1.read())
        f1.seek(0,0)
        print(f1.read())
    with open('users.txt','w+',encoding='utf-8') as f2:
        f2.write('egon/alex')
        f2.seek(0,0)
        print(f2.read())
    with open('users.txt','a+',encoding='utf-8') as f3:
        print(f3.read())
        f3.seek(0,0)
        print(f3.read())
    

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

    with open(r'D:python之路users.txt','rb') as f:
        f.seek(0,2)
        while True:
            a = f.tell()
            while True:
                f.seek(a,0)
                l = f.read()
                if l:
                    print(l.decode('utf-8'))
                    break
                else:
                    continue
    

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

    user = input('请输入账号:')
    pwd = input('请输入密码:')
    with open('users1','r',encoding='utf-8') as f:
        for line in f:
            user1, pwd1 = line.strip().split(':')
            if user1 == user and pwd1 == pwd:
                print('登陆成功')
                break
        else:
            print('登录失败')
    
    4.2:编写程序实现用户注册后(注册到文件中),可以登录(登录信息来自于文件)
    
    while True:
        user = input('请输入账号:').strip()
        pwd = input('请输入密码:').strip()
        pwd1 = input('确认密码:').strip()
        if user:
            if pwd == pwd1:
                with open('users.txt','a',encoding='utf-8') as f:
                    f.write('{}:{}
    '.format(user,pwd))
                print('注册成功')
                break
            else:
                print('密码不一致')
        else:
            print('账号不能为空')
    tag = True
    while tag:
        name = input('请输入账号:').strip()
        pwd5 = input('请输入密码:').strip()
        with open('users.txt','r',encoding='utf-8') as f1:
            for line in f1:
                name1, pwd0 = line.strip().split(':')
                if name == name1 and pwd0 == pwd5:
                    print('登陆成功')
                    tag = False
                    break
            else:
                print('登陆失败')
    
  • 相关阅读:
    RabbitMq 集群配置
    获取 input 单选框和多选框的值
    js 获取 通过 ”?“ 或者 ”&“ url 传过来参数值
    Java 对文件的读取操作
    java 链接jdbc
    了解EBP寄存器
    节后后遗症
    [转]web service实现原理与异步调用
    Javascript实现无刷新分页
    邮件发送
  • 原文地址:https://www.cnblogs.com/pythonwl/p/12506135.html
Copyright © 2011-2022 走看看