'I am trying to print all of the logged-in users tasks from a file(tasks.txt) in a more user-friendly manner. This is what I have so far
I am trying to print all of the logged-in users tasks from a file(tasks.txt) in a more user-friendly manner.
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))
Solution 1:[1]
first you have to define userligin in line 8 or if it is string you have to put it in "" i hope that works for you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mohammedy |