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('账号或密码错误')
    
  • 相关阅读:
    JS相关
    简单的打字效果
    android文件保存
    android 各种布局技术
    Android中的显示单位
    第一个android项目目录结构说明
    安装运行第一个android应用
    android手机模拟器屏幕分辨率说明
    系统常用VC++运行时下载地址
    VC++共享文件夹
  • 原文地址:https://www.cnblogs.com/zuiyouyingde/p/12515192.html
Copyright © 2011-2022 走看看