zoukankan      html  css  js  c++  java
  • 作业0317

    1、编写文件修改功能,调用函数时,传入三个参数(修改的文件路径,要修改的内容,修改后的内容)既可完成文件的修改

    def modify(Absolute_Path,old_contents,new_contents):  # x——修改的文件路径,y——要修改的内容,z——修改后的内容
        '''文件修改功能,调用函数时,传入三个参数(修改的文件路径,要修改的内容,修改后的内容)既可完成文件的修改'''
        with open(Absolute_Path, mode='rt', encoding='utf-8') as f:
            res = f.read()
            data = res.replace(old_contents,new_contents)
            print(data)
    
        with open(x, mode='wt', encoding='utf-8') as f1:
            f1.write(data)
    

    2、编写tail工具

    def tail(Absolute_Path):
        '''编写tail工具,路径为绝对路径'''
        import time
        with open(Absolute_Path, mode='rb') as f:
            f.seek(0, 2)
    
            while True:
                line = f.readline()
                if len(line) == 0:
                    time.sleep(0.3)
                else:
                    print(line.decode('utf-8'), end='')
    

    3、编写登录功能

    def login(Absolute_Path):
        '''编写登录功能,路径为绝对路径'''
    
        username = input('请输入您的账号:').strip()
        password = input('请输入您的密码:').strip()
    
    

    4、编写注册功能

    def signin(Absolute_Path):
        '''编写注册功能,路径为绝对路径'''
    
        username = input('请输入用户名: ')
        password = input('请输入密码: ')
        with open(Absolute_Path, 'w', encoding='utf-8') as f:
            f.write('%s:%s' % (username, password) + '
    ')
    

    5、编写用户认证功能

    def Certification(Absolute_Path):
        '''编写认证功能,路径为绝对路径'''
    
        username = input('请输入您的账号:').strip()
        password = input('请输入您的密码:').strip()
    
        with open(Absolute_Path,'r') as f:
            res=f.read()
    
            user,pwd=res.strip().split(":")
            for x in range(0,3):
                if user == username and pwd == password:
                    print('login successful')
    
                else:
                    print('账号或密码错误')
    
  • 相关阅读:
    用成员函数指针作为Callback
    在ubuntu上编译gcc会到的问题及解决方法
    异步
    棋牌游戏服务器架构: 详细设计(二) 应用层设计
    elementUI eltable添加序号列
    vue 父子组件的相互调用
    所谓编程的哲学艺术
    亲爱的百度,您带着bug翩翩走来……呃
    std::vector<point>对距离固定点的距离排序
    升级ubuntu11出现grub错误
  • 原文地址:https://www.cnblogs.com/zuiyouyingde/p/12515192.html
Copyright © 2011-2022 走看看