作业03-17

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

"""

def revise_file(file_path,change_content,data):

    """对文件内容时行修改"""

with open(file_path,"r",encoding="utf-8") as f:

info = f.read()

info = info.replace(change_content,data)

with open(file_path,"w",encoding="utf-8") as f:

f.write()

"""


# 2、编写tail工具

"""

import time

def tail():

with open("access.log","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=" ")

tail()

"""


# 3、编写登录功能

# 让用户输入账号和密码,并格试化方试打印出来

"""

def log_system():

username = input("your name:")

password = input("your pwd:")

    print(f"用户的账号密码是:{username}{password}")

    # 打开文件user.txt校验用户信息with open("user.txt", "r", encoding="utf-8") as f:

# content = f.read()

for line in f:

user, pwd = line.strip().split(":")

            # 判断用户登录信息if username == user and password == pwd:

print("login sucessful")

break

else:

print('login failed')

break

log_system()

"""


# 4、编写注册功能

"""

def rejister():

#用户输入账户和密码while True:

username = input("your name:")

password = input("your pwd:")

    #打开文件校验追加用户信息with open(r"user.txt","a",encoding="utf-8") as f:

            f.write("{}:{}\n".format(username,password))

rejister()

"""


©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容