![]() ![]() Now you can easily remove the tasks from the list and write them again in the txt file instead of appending it and creating duplicates. Tasks = # Remove newline characters from each line ![]() with open("task_list.txt", "w") as f:Īnd then use f.readlines instead and then use a list comprehension to save the tasks in tasks try: txt file because "a" is for append and it will duplicate the tasks in. and when you enter the task to remove from the list it gives you a "ValueError" and the program stops.įirst of all, use "w" instead of "a" when you are writing the tasks in. so when the program runs it doesn't save the tasks inside the file to the tasks= list. Its because in try block you are using tasks = text.split(',') it uses "," as a delimiter, meanwhile you are using "\n" as a delimiter here f.write(i "\n") when you are writing the tasks inside the. But I want to have a save option in order no to lose the tasks I've added once, as well as being able to add or remove any element (task) to/from the list. txt file doesn't exist, it just run the program itself. txt where takes the elements for the list 'tasks'Įxcept FileNotFoundError: # If that. Try: # Here, Python discovers if already exist a. Os.system('cls') # This manteins the terminal cleaned. ![]() Print(margin 'Selcet one of the options writing one of the numbers avaibles.') txt file in order to save the tasks list for a future running of the program. Menu = int(input(margin '1) Add task\n%s2) Remove task\n\n%s3) CREDITS\n%s4) BUGS\n\n%s5) CLOSE\n\n'%(margin, margin, margin, margin)))Įlif menu = 5: # Before the program closes, writes an. Print(margin '* When an element is wrote to be removed -in 2) Remove task- from list, the program closes suddenly')įor i in tasks: # Prints the tasks list elements on the terminal Print(margin '* The program closes by pressing ENTER when it isn\'t expecting that key to be pressed.') Print(margin '* If an integer isn\'t wrote on the menu, the program closes suddenly.') Input(margin 'Press ENTER to go back to menu.') Print(margin 'What is new compared to v0.1 is that tasks are now saved everytime you close de program from the menu.') Print(margin 'You can add and remove any number of elements to the task list.') Print(margin 'In this version, tasks are showed in a list above of the terminal.') Print(margin 'TaskManager version 0.2, created by Vicente Pascual Llinares in 05/2023.') Return tasks.remove(input('REMOVE TASK: ')) This is the list in which the user adds or remove elementsĭef add_task(): # Adds an element to the var: tasksĭef remove_task(): # Removes an element from the var: tasks Margin = " " * 5 # Just a margin in order to clear the terminal on the print() functions. Here is the program, you can just copy it and run it in your computer if you want: # TASK MANAGER v0.2 ENGLISH VERSION I have more bugs, but just wanna ask for that one. I'm learning programming by self-teaching since a few weeks before starting the career, so I'll appreciate your help so much. txt file and add the elements from it to the list. txt file exists: if it doesn't, the program just runs if it already exists, Python read the. Moreover, the first time the program is executed, it search if the. txt file is saved everytime the terminal is closed from the program's menu option. Nevertheless, while testing the program, I figured out that when I try to remove an element from the list, the terminal closes suddenly. txt file so that they can be still being able to be managed (added/removed from the list) the next time the program is opened. The tasks are added to a list and saved in a.
0 Comments
Leave a Reply. |