1 00:00:00,610 --> 00:00:05,740 All right, now it is time for that button, find your input output. 2 00:00:06,730 --> 00:00:07,990 And how to handle it. 3 00:00:08,240 --> 00:00:15,670 OK, so you want to read fine to open fire for writing to open fire already existed for writing or. 4 00:00:16,540 --> 00:00:24,070 Append to a specific file we would use, and actually this is supported in the but you'd know how to 5 00:00:24,070 --> 00:00:24,570 do that. 6 00:00:24,610 --> 00:00:26,220 Actually, it is like this. 7 00:00:26,230 --> 00:00:34,810 So first declare a variable name, I would name it in my case, F, which is the first file I will use 8 00:00:34,810 --> 00:00:35,750 the open function. 9 00:00:36,100 --> 00:00:38,610 This is to open a file description. 10 00:00:39,550 --> 00:00:41,480 Then it has the following. 11 00:00:41,560 --> 00:00:43,870 So it has the first parameter. 12 00:00:43,870 --> 00:00:44,830 The second parameter. 13 00:00:45,040 --> 00:00:46,990 The first parameter is the name of the file. 14 00:00:47,230 --> 00:00:49,330 OK, so I will name it whatever I want. 15 00:00:49,900 --> 00:00:56,260 And you can choose this file to be either read, write, read, tried to up into it if it is already 16 00:00:56,260 --> 00:00:57,100 existed or not. 17 00:00:57,170 --> 00:01:01,840 Now actually that depends on the mode, which is the second parameter here. 18 00:01:02,140 --> 00:01:08,950 But in my case I'm using that read mode, which is I want to read a file that already existed. 19 00:01:09,190 --> 00:01:10,380 So I would return here. 20 00:01:10,810 --> 00:01:16,090 And by the way, you can see that the amended by here it is here inside the Python files, if you remember 21 00:01:16,990 --> 00:01:18,570 what we did previously. 22 00:01:18,970 --> 00:01:26,080 So you can see that now I will create a text file here and I will name this to the text, OK? 23 00:01:26,410 --> 00:01:29,560 And I will put here, as you can see, some values inside it. 24 00:01:30,190 --> 00:01:30,620 Yeah. 25 00:01:31,060 --> 00:01:37,330 By the way, I'm using the equal command and the touch command to create the text file and to add this 26 00:01:37,750 --> 00:01:40,020 specific value, which is the same values inside it. 27 00:01:40,270 --> 00:01:41,180 Actually, it's up to you. 28 00:01:41,180 --> 00:01:43,210 You can use whatever you want. 29 00:01:43,750 --> 00:01:44,230 No big deal. 30 00:01:44,770 --> 00:01:49,270 So actually, let's open this file and I'm using them, by the way, here. 31 00:01:49,720 --> 00:01:55,570 So let's put like two arbitrary values line whatever. 32 00:01:56,890 --> 00:02:03,850 And here is in occupied, for example, or end of the line. 33 00:02:04,210 --> 00:02:06,730 OK, last line, for example. 34 00:02:06,880 --> 00:02:08,940 OK, and let's save it. 35 00:02:08,950 --> 00:02:16,480 By the way, if you don't like them, I recommend you to learn it to know how to use it for actually 36 00:02:16,480 --> 00:02:18,300 it's very Boltwood Ed. 37 00:02:18,760 --> 00:02:25,750 Yeah I know it is old fashioned Izzet say but actually for you as a high Batista cybersecurity engineer, 38 00:02:25,870 --> 00:02:28,950 it's important actually and very recommended. 39 00:02:28,960 --> 00:02:32,500 I recommend you a lot to learn about it and its shortcut. 40 00:02:32,500 --> 00:02:33,940 It's powerful. 41 00:02:34,240 --> 00:02:35,460 Use it anyway. 42 00:02:36,570 --> 00:02:43,110 Just use any tuxedoed for now, if you are not familiar with them and what arbitrary value inside that 43 00:02:43,110 --> 00:02:49,530 is the text file that that already here inside the same level of the amended by that we are writing 44 00:02:49,710 --> 00:02:50,680 and now its name. 45 00:02:50,750 --> 00:02:55,110 So just the text file and open it for it. 46 00:02:55,140 --> 00:02:55,540 OK. 47 00:02:55,800 --> 00:02:56,270 All right. 48 00:02:56,520 --> 00:02:59,340 Now I want to print the content of this file. 49 00:02:59,570 --> 00:03:01,520 I will use that lead function. 50 00:03:01,530 --> 00:03:06,780 So F which is the name of the variable that we thought this thing and I would use it. 51 00:03:07,020 --> 00:03:14,550 OK, so this will read the whole content of this text file, but it will not be printed because the 52 00:03:14,550 --> 00:03:16,490 output will be here. 53 00:03:16,650 --> 00:03:23,640 So I will use the print function for that and then I will I will print the read like this. 54 00:03:23,670 --> 00:03:30,630 So actually if I go there and read and see if it is will show us what we need. 55 00:03:31,140 --> 00:03:34,680 So if I type that by three men, yeah. 56 00:03:34,860 --> 00:03:40,890 You can see it is as expected, the same values line to blah blah blah until we reach the end of line 57 00:03:40,890 --> 00:03:41,400 last night. 58 00:03:41,430 --> 00:03:41,830 OK. 59 00:03:42,150 --> 00:03:48,960 So as you can see, we opened this file, Fareed, as you can see, the note is read and that is the 60 00:03:48,960 --> 00:03:51,680 text file is there and existed. 61 00:03:51,750 --> 00:03:59,560 But what if we want this to actually and try to read this and actually read to the text is not here. 62 00:03:59,760 --> 00:04:01,890 So as you can see, no such file or directory. 63 00:04:03,300 --> 00:04:05,370 Now, I actually don't worry about this. 64 00:04:05,370 --> 00:04:07,620 We will handle it in the next picture immediately. 65 00:04:07,800 --> 00:04:10,140 How to handle the errors in the file. 66 00:04:10,680 --> 00:04:13,260 And you know, it is not something big deal. 67 00:04:13,470 --> 00:04:17,000 It is the same way as what we learned previously from the error handling. 68 00:04:17,430 --> 00:04:24,250 And you can see that we will start using specific file errors or specific errors inside the accept. 69 00:04:24,280 --> 00:04:27,090 OK, anyway, until that time, it's not OK. 70 00:04:27,480 --> 00:04:30,630 For now, let's open a fight for writing. 71 00:04:30,630 --> 00:04:31,920 So this tool. 72 00:04:31,920 --> 00:04:34,200 But this time the more I will use it for. 73 00:04:34,200 --> 00:04:34,560 Right. 74 00:04:34,920 --> 00:04:36,670 Which means I want to write inside. 75 00:04:36,900 --> 00:04:37,200 OK. 76 00:04:37,410 --> 00:04:43,910 And this time I will add this content so it can content equal. 77 00:04:44,280 --> 00:04:45,600 And this is the content. 78 00:04:45,810 --> 00:04:50,520 I want this new content to be overwrite, overwritten onto this text to file. 79 00:04:50,520 --> 00:04:53,660 But actually it had it is empty and it is not existed. 80 00:04:54,000 --> 00:04:56,740 So yeah, this is the only data it will be. 81 00:04:56,940 --> 00:04:58,720 So some content, OK. 82 00:04:59,040 --> 00:05:05,580 And for that I would use this time I will use that of the right function. 83 00:05:06,150 --> 00:05:13,350 OK, so the right function here, it would write to this f that we open it for writing and what we would 84 00:05:13,350 --> 00:05:19,020 write, we would write the content, the content variable, as you can see, content like this. 85 00:05:19,290 --> 00:05:20,980 And here this is the variable. 86 00:05:21,540 --> 00:05:25,020 And finally, after it is, everything is correct. 87 00:05:25,290 --> 00:05:32,440 We want to print and read what inside this this to it should because some content right now. 88 00:05:32,480 --> 00:05:34,170 Let's check it out actually. 89 00:05:35,190 --> 00:05:38,180 Yeah, you can see the fine is not readable. 90 00:05:38,730 --> 00:05:43,680 Yeah, you may ask me, but what happened when maybe you forget something actually. 91 00:05:44,520 --> 00:05:46,130 Well this f the three. 92 00:05:46,830 --> 00:05:48,720 Yeah, we open it as what. 93 00:05:49,050 --> 00:05:49,720 As Right. 94 00:05:49,770 --> 00:05:52,260 So how to read something open as I write. 95 00:05:52,530 --> 00:05:53,530 This is not right. 96 00:05:53,610 --> 00:05:53,910 Right. 97 00:05:53,910 --> 00:05:54,220 Right. 98 00:05:54,750 --> 00:05:59,940 So how to do thinking about it when actually we will use the closed function. 99 00:05:59,940 --> 00:06:00,510 So F. 100 00:06:01,520 --> 00:06:10,790 The clothes function, so this will close the final description that we open it as right, then we can 101 00:06:11,390 --> 00:06:18,770 create a new variable and use the open function and name it just to the text. 102 00:06:19,610 --> 00:06:23,420 And this time we would open it as read, not as a write. 103 00:06:23,720 --> 00:06:26,960 And then we can read this out and it should be working. 104 00:06:27,290 --> 00:06:28,760 All right, let's check this out. 105 00:06:29,060 --> 00:06:36,140 So the screen, the screen first and you can see it is working as expected and which is some content. 106 00:06:36,170 --> 00:06:38,000 OK, so far, so good. 107 00:06:38,240 --> 00:06:47,750 All right, Andrea, regarding the models actually and the functions for that, I hope you can just 108 00:06:47,750 --> 00:06:54,050 open your browser and type Biton or models. 109 00:06:54,950 --> 00:06:57,290 And from there you can see there are a lot of. 110 00:06:58,340 --> 00:07:03,620 And from there, you can see there are a lot of websites differences, but actually I recommend you 111 00:07:03,620 --> 00:07:09,830 to go to the official documentation because there you can see that there are a lot of exemptions and 112 00:07:10,130 --> 00:07:11,280 functions you can use. 113 00:07:11,690 --> 00:07:15,210 So, yeah, I need to go to the I want to start with you here. 114 00:07:15,590 --> 00:07:15,950 Yeah. 115 00:07:15,950 --> 00:07:17,720 Here you can see that we can add. 116 00:07:19,070 --> 00:07:26,450 This is the open the encoding, so you can see that we have mode's this time and don't worry, I will 117 00:07:26,450 --> 00:07:27,880 show you the mods right away. 118 00:07:28,310 --> 00:07:29,140 Just quickly. 119 00:07:29,150 --> 00:07:33,140 I mean, so here you can see that we have a lot of functions actually. 120 00:07:33,560 --> 00:07:40,130 So you can see that the flash closed is setit readable with line with lines. 121 00:07:40,130 --> 00:07:41,170 Seage tell. 122 00:07:41,300 --> 00:07:46,790 Actually a lot of functions can be used and useful can be depends on the situation you want. 123 00:07:47,400 --> 00:07:50,510 So actually if I go to this website. 124 00:07:51,630 --> 00:07:53,730 I just want to show you something here. 125 00:07:54,780 --> 00:08:00,750 The mods, actually, you can see these are the mods that are available on Biton. 126 00:08:01,620 --> 00:08:09,060 So, yeah, you can see that we have read we have read Binary or A, B or B, so this is to read in 127 00:08:09,060 --> 00:08:16,800 binary format only we have X hour plus, which means read, as you can see, five for both read and 128 00:08:16,800 --> 00:08:17,160 write. 129 00:08:17,190 --> 00:08:22,890 OK, so not just for reading it, you can be for reading and writing and you can see that the bones 130 00:08:22,890 --> 00:08:26,580 are placed at the beginning of the far right we have right. 131 00:08:26,580 --> 00:08:29,700 We have our B plus which is read binary. 132 00:08:30,390 --> 00:08:31,770 We have right. 133 00:08:31,770 --> 00:08:32,100 Right. 134 00:08:32,100 --> 00:08:33,770 Binary plus. 135 00:08:33,930 --> 00:08:40,260 And as you can see here, the plus is for read and write, but this time over time overwrite the existing 136 00:08:40,260 --> 00:08:40,620 file. 137 00:08:40,740 --> 00:08:44,190 If it exists, if it does not exist, it will create a new file. 138 00:08:44,220 --> 00:08:53,220 OK, and the same for the B plus there is binary plus for event and this is something new and we have 139 00:08:53,220 --> 00:09:00,330 a B appended for the binary and we have a benefit for both reading and binary in a binary format because 140 00:09:00,330 --> 00:09:06,150 this is a B plus by the way, and the pointer will be at the end of the file if it exists. 141 00:09:06,180 --> 00:09:06,490 OK. 142 00:09:06,840 --> 00:09:07,310 All right. 143 00:09:07,650 --> 00:09:08,480 Have a look there. 144 00:09:08,720 --> 00:09:10,980 Try this out if you are interested. 145 00:09:11,220 --> 00:09:18,090 Now in the next picture, we will talk about the error handling for the python finds out when we open 146 00:09:18,090 --> 00:09:18,510 a fight. 147 00:09:18,690 --> 00:09:23,010 That's why it is not existed, how to handle such errors in a very smooth way. 148 00:09:23,160 --> 00:09:23,520 All right. 149 00:09:23,520 --> 00:09:24,360 Thanks for watching.