I'm building a task manager and I need to find tasks assigned to a user who is logged in. My re.findall() won't display chosen content. This is the chosen task output when user admin is logged in
Task: Register Users with taskManager.py
Assigned to: admin
Date assigned: 10 Oct 2019
Due Date: 20 Oct 2019
Task Complete: No
Task Description:
Use taskManager.py to add the usernames and passwords for all team members that will be using this program.
Task: Assign initial tasks
Assigned to: admin
Date assigned: 10 Oct 2019
Due Date: 25 Oct 2019
Task Complete: No
Task Description:
Use taskManager.py to assign each team member with appropriate tasks
This is the txt file that contains all that info
admin, Register Users with taskManager.py, Use taskManager.py to add the usernames and passwords for all team members that will be using this program., 10 Oct 2019, 20 Oct 2019, No
admin, Assign initial tasks, Use taskManager.py to assign each team member with appropriate tasks, 10 Oct 2019, 25 Oct 2019, No
chris, build task manager, finish manager, 29 June 2022, 22 May 2025, No
my code
elif menu == "vm":
find_tasks = input("Please enter your username: ")
with open(r"C:\Users\27711\Desktop\PROGRAMMING\Bootcamp lvl 1\task 20 Capstone\tasks.txt",'r') as file3:
found = re.findall('.*\n*Assigned to:.*\n*(' + re.escape(find_tasks) + ')\n*Task:\n*(.*)\n*Date assigned:(.*)\n*Due Date:(.*)\n*Task Complete:(.*)\n*Task Description:\n*(.*)\n*', file3.read())
for item in found:
print(f'''\nTask:\t {item[1]}
\nAssigned to:\t {item[0]}
\nDate assigned:\t {item[2]}
\nDue Date:\t {item[3]}
\nTask Complete:\t {item[4]}
\nTask Description: \n{item[5]}\n''')
Then this is the output I get on terminal it stops directly after I enter the username (I only added this new input in to test otherwise I use the main user/login name that you input in the beginning of the task manager)
Please enter your user name: admin
Login name: admin Found in System
Please enter a password for admin: adm1n
Succesfully logged in!
Please choose from the following options
r- register user
a- add task
va- view all tasks
vm- view my tasks
e- exit
- vm
Please enter your username: admin
Task:andAssigned to:in your pattern differs to the input. Might also be an idea to use\s*(any whitespace) instead of all these.*\n*but no idea how input could look like. Try like this. - bobble bubble' + re.escape(find_tasks) + 'withadminto match the sample content (on top of your question). Best to play with your pattern and input in regex101 or some other regex testing tool until it matches. - bobble bubble