作业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()

"""


你可能感兴趣的:(作业03-17)