1
00:00:00,510 --> 00:00:08,210
Okay so I have these fruits.txt file in here which has these four lines which are not fruits anyway,

2
00:00:08,250 --> 00:00:09,970
but you get the idea.

3
00:00:09,990 --> 00:00:10,920
It's text.

4
00:00:11,010 --> 00:00:16,080
We want to add two more lines to these existing fruits.txt file.

5
00:00:16,080 --> 00:00:20,400
We don't know what is there at the moment.

6
00:00:20,400 --> 00:00:26,310
If you look at the open documentation and scroll down you'll see

7
00:00:29,820 --> 00:00:35,360
here that you can pass different moods in these argument here.

8
00:00:35,460 --> 00:00:37,260
So are which we used already.

9
00:00:37,290 --> 00:00:42,480
We used w and then you have x, if you use x

10
00:00:45,630 --> 00:00:48,280
and try to write let's say okra.

11
00:00:49,620 --> 00:00:54,450
If you execute that it's going to say that file exists.

12
00:00:54,480 --> 00:01:01,350
So unlike the w modes which overwrites a file, X will not overwrite the file if the file exists.

13
00:01:01,350 --> 00:01:07,930
However it cannot append contents to an existing file because it says that the file exists.

14
00:01:08,070 --> 00:01:11,280
Therefore we jump to the next mode which is a.

15
00:01:15,610 --> 00:01:22,090
You see that okra was added there of course with a small issue because there was not a break line here

16
00:01:22,180 --> 00:01:24,320
in the text, in the existing text file.

17
00:01:24,370 --> 00:01:26,560
So that's some information you should know.

18
00:01:26,560 --> 00:01:32,710
And if you know there is no break line, then you'd need to, let me save this text file, then you'd need to

19
00:01:33,070 --> 00:01:39,270
add a break line there to get the correct outputs.

20
00:01:39,310 --> 00:01:44,760
So anytime you add a new line you'd need to add a break line in front.

21
00:01:44,770 --> 00:01:48,580
Now how about reading that content?

22
00:01:52,410 --> 00:01:58,320
Maybe saving it you save it in a variable and print out the content.

23
00:01:58,680 --> 00:01:59,730
Will it work?

24
00:01:59,730 --> 00:02:00,930
I don't think so.

25
00:02:01,020 --> 00:02:06,550
It says that the operation is not supported, the file is not readable.

26
00:02:06,780 --> 00:02:16,110
It's a which is for appending, if you want to appen, to write, and read at the same time you want

27
00:02:16,110 --> 00:02:17,340
to add a plus.

28
00:02:21,130 --> 00:02:24,490
Just like that, execute.

29
00:02:24,820 --> 00:02:27,090
You get an empty output.

30
00:02:27,100 --> 00:02:28,200
Why?

31
00:02:28,540 --> 00:02:30,510
Because of the cursor.

32
00:02:30,580 --> 00:02:40,320
So what's happened is that when we added the okra line there so at first you created the file here.

33
00:02:40,330 --> 00:02:42,630
At this point the cursor is here.

34
00:02:42,640 --> 00:02:43,310
OK.

35
00:02:43,420 --> 00:02:52,460
Then you write the file in this line the cursor goes to the ends of the file.

36
00:02:52,460 --> 00:02:59,450
So when you read now you read whatever is left under the last line which is nothing.

37
00:02:59,690 --> 00:03:09,650
What you can do is my file seek, apply a seek method to put the curse at the zero position once again.

38
00:03:11,570 --> 00:03:15,370
In that case the cursor will go to the end.

39
00:03:15,560 --> 00:03:16,920
It will go again

40
00:03:17,040 --> 00:03:19,050
at the zero position with this line.

41
00:03:19,370 --> 00:03:23,860
And then you'll read everything from there and down.

42
00:03:24,470 --> 00:03:26,390
So you get the correct output.

