我正在尝试以一种更用户友好的方式从一个文件(tasks.txt)中打印所有登录用户的任务.这就是我到目前为止所拥有的



我正在尝试以更用户友好的方式从文件(tasks.txt(中打印所有登录用户的任务。

def view_mine():
print("My Tasks")

# Read the task from task.txt file
with open ('tasks.txt', 'r') as f:
lines = f.readlines()

# Check if the username of the person logged in is the same as the username you have read from the file
loginUsername = user_login
userTasks = [line for line in lines if line.lstrip().startswith(loginUsername)]
print(''.join(userTasks))

首先必须在第8行中定义userligin或者如果它是字符串,你必须把它放在"字符串"中"我希望这对你有效

最新更新