Hello, everyone, welcome to the last application in this course, to do this application. Hope you're excited about it. Let's start. First we created to do these costs. The first thing is to create an initialization method that you find in dead cells as the first parameter file name as the second parameter. In this class, we have two class well people.
The first one is to store the file name. The second one is to store the full list of tasks. to initialize the task, we need to read that Task from the file. So let's define another function load file into this. To do that, first we create an empty task this data then the way to file is file for cost in file costs a pen cost on the strip. As discussed in the previous video, the task will come with a newline character at the end, too with morfitt.
We're used to a strip function Okay, before task is loaded to the list and we kind of task And then let's define a function to list all the tasks in the to do lists. List task. So for index pause in a normal way. So we start with one, then we're printing in this price, and then the task name. Okay, let's see how things go. Okay, let's see how things go.
We create an instance of the to do lists with to do list of tasks as the file name and then with this, the task Let's see how that works. Right and create all the tasks from the file. The next function we are going to implement is right into file. So we want to write all the tasks we have back to the file. We create a function right into file, then open the file. This time we use the right mode.
So we write all the task back to the file as there's no new like haircutter e task lists, we need to add it here. With the right into file function now we can add tasks to the hospice. Define add task. Take the horse as a parameter. Then we add it to the task list. Then we write the task list to define.
So let's see how things go. to totally stop at task by goals and then release the class again. Let's add some words here. For everything so we have some print statements to show you was the list before adding the towers and was the lease after entering the past. Let's see. Before adding the tags, we have four items.
After adding the task, we have five items. That's good. Now let's implement the last function of the to do this mark a task as done, defined, done task sell us. Next, we are going to ask the user to put in the number one, two people instead of typing the whole task description so How do we get the transponder number. So self dot pass as the list, then we can actually specify the index here to get the task index. But do you remember the Python lists start with zero, but this this stuck with one, so we need to minus one on the index.
Therefore, if we get one from this list, we minus one then we can see Oh, there will be the task at zero, which is the first item in the list. So this is the task we want to delete. So we use the DDL function. After we delete the task that we have done, we need to wait the whole task this to the file South Dakota right into file. But this is not all. What if the user type in some number that is way beyond the number.
And the lady is like 24 displays. So we use try, except to handle that. We try to do that. After user input, some number that is way beyond number of tasks we have. We have the index URL we should pray is no open task. We're all mad.
Okay. That's how we mark a task is done. Let's try that. Before marking the stone done toss marking a task I see how things go. I forgot the color. Let's try again.
Yes, this is before marking a task is done. I marked the first one as done. So as we move Okay, that's part one of our project. We have implement order function we need further to do this task. In the next video, we're going to create a menu. See you