1
00:00:00,120 --> 00:00:09,480
Previously, we wrote a script to which concatenated all these files, and we ended up with this merger

2
00:00:09,480 --> 00:00:17,610
that see us before, but we have these headers repeating in every X number of rows, so we want to do

3
00:00:17,610 --> 00:00:18,120
this again.

4
00:00:18,120 --> 00:00:24,990
But without the headers, without this and without that, just this one.

5
00:00:26,270 --> 00:00:35,030
So we import path, we create a path object for the directory, which contains the files we iterate

6
00:00:35,030 --> 00:00:36,500
over those files.

7
00:00:36,740 --> 00:00:46,520
We open each file, we read the content and then we add that contents to an empty string, so we keep

8
00:00:46,520 --> 00:00:48,050
adding to that string.

9
00:00:48,350 --> 00:00:53,450
But this time, we don't want to add the first line.

10
00:00:54,260 --> 00:01:00,830
In that case, we want to treat the content on a line by line basis.

11
00:01:01,460 --> 00:01:10,430
So currently, we have the content stored in this content variable as a string one single string that

12
00:01:10,430 --> 00:01:12,960
happens when you use the leads methods.

13
00:01:12,980 --> 00:01:18,260
But if you use the read lines, what we get is a list.

14
00:01:18,530 --> 00:01:22,460
Let's try that to you with open files, for example.

15
00:01:23,000 --> 00:01:28,130
File for that See as V in read mode as file.

16
00:01:31,300 --> 00:01:35,170
Content illegal to file that reads lines.

17
00:01:35,770 --> 00:01:38,230
Let's see what content is this time.

18
00:01:38,500 --> 00:01:41,220
So it's a list of strings.

19
00:01:41,230 --> 00:01:44,260
Each string represents one line.

20
00:01:44,470 --> 00:01:47,230
So is the first line and the break line as well.

21
00:01:47,700 --> 00:01:51,670
Backslash and the second line with a break line and so on.

22
00:01:52,900 --> 00:01:57,630
So now that we have this content list, we want to filter that out.

23
00:01:57,700 --> 00:02:04,630
So let's say new content is equal to content and we get all the items of the list.

24
00:02:05,530 --> 00:02:06,670
But the first one?

25
00:02:07,090 --> 00:02:11,470
So in other words, we get from the item with index one.

26
00:02:11,650 --> 00:02:13,510
This has an index of one.

27
00:02:13,780 --> 00:02:16,420
This is an index of two, three and so on.

28
00:02:16,630 --> 00:02:21,520
So we don't get the item with index zero, which is the first line.

29
00:02:22,900 --> 00:02:30,280
Of course, this will do this filtering for all of the files, but we need the header for the first

30
00:02:30,610 --> 00:02:31,600
file rights.

31
00:02:31,870 --> 00:02:41,710
So we want to do some sort of, if conditional here, rights somewhere in here.

32
00:02:42,820 --> 00:02:48,010
So we could say something like if index equal to zero.

33
00:02:49,380 --> 00:02:58,050
I'll tell you what index is in just a bit then, so if we're dealing with the first file, which will

34
00:02:58,050 --> 00:03:06,060
have an index of zero in the loop, then we want to do merged or yeah, we want to do this here.

35
00:03:06,900 --> 00:03:10,440
Merge a single to merge plus content.

36
00:03:12,120 --> 00:03:18,120
Ale's merge, a single to merge, plus new content.

37
00:03:18,450 --> 00:03:20,700
Plus that's backslash.

38
00:03:23,540 --> 00:03:31,250
Now, what is index index now could be for index five path in enumerate?

39
00:03:33,390 --> 00:03:39,180
That so that's a sane list, and I'll show you what this does.

40
00:03:39,570 --> 00:03:49,920
Let's suppose we have the list of file paths for the paths and which looks something like file for the

41
00:03:49,920 --> 00:03:55,140
C as V file five, the C as V and so on.

42
00:03:55,140 --> 00:04:05,670
Let's keep it with two only now when you do four index file path in enumerate file paths.

43
00:04:12,200 --> 00:04:17,480
Index will be the index of each of these.

44
00:04:18,550 --> 00:04:19,149
Items.

45
00:04:19,899 --> 00:04:27,760
So this is a way to extract the index, and therefore we see if index is equal to zero, then we don't.

46
00:04:28,960 --> 00:04:36,310
Remove the heads or so we use the contents as it is, otherwise we use the new contents, which does

47
00:04:36,310 --> 00:04:37,330
not have the header.

48
00:04:38,710 --> 00:04:39,040
Right.

49
00:04:39,610 --> 00:04:49,450
And then finally, we write the merged file in this file, so merge the CSB and we should be ready to

50
00:04:49,450 --> 00:04:50,050
run this.

51
00:04:50,620 --> 00:04:51,160
So run.

52
00:04:51,970 --> 00:04:59,080
Yes, we do get this error because it's trying to concatenate string with a list.

53
00:04:59,710 --> 00:05:03,520
So contents here is a list and merge these a string.

54
00:05:03,820 --> 00:05:14,170
So we want to convert that contents into a string because you saw that content was something like I-D

55
00:05:14,170 --> 00:05:16,600
and units and so on.

56
00:05:17,560 --> 00:05:23,260
We want to concatenate that's using the join method, which works like this.

57
00:05:23,440 --> 00:05:32,860
If you have, for example, a small string such as adults and you say, join this Join methods.

58
00:05:32,860 --> 00:05:42,340
If you give it a list as inputs and you have some lines such as B, C, some items D E F and you execute

59
00:05:42,340 --> 00:05:49,780
this, the join method will make a string out of those items and it will join them with these dots.

60
00:05:50,020 --> 00:05:53,800
So if you had other items, the dots goes between the items.

61
00:05:53,800 --> 00:05:54,310
Always.

62
00:05:57,880 --> 00:06:02,530
As you can see here, no evidence is an empty string.

63
00:06:03,910 --> 00:06:05,050
What you get is this.

64
00:06:06,340 --> 00:06:12,310
So nothing is applied between the items, but still you get one single string.

65
00:06:13,150 --> 00:06:15,940
So now let's convert.

66
00:06:16,270 --> 00:06:24,280
Where do we do the conversion before we do that, before we append content to merged?

67
00:06:24,910 --> 00:06:31,360
So just before the first conditional a string join content.

68
00:06:32,610 --> 00:06:34,980
So that is equal to content.

69
00:06:37,010 --> 00:06:41,720
You can override the existing variable, so right, the screen there currently, we have the least now

70
00:06:41,720 --> 00:06:44,000
where the string content is equal to that.

71
00:06:45,770 --> 00:06:54,320
The same we do for the else, Port New Contents, a sequel to that, but join.

72
00:06:55,810 --> 00:07:02,050
New content, then we have pens, new content to emerge, so run that.

73
00:07:03,760 --> 00:07:08,710
Go to merchants and sweet gets what we were asking for.

74
00:07:08,800 --> 00:07:15,640
So the heads are in the first line, then we have the first line with dots, our second thoughts and

75
00:07:15,640 --> 00:07:20,620
then comes the delta of the second file and then comes the delta of the third file.

76
00:07:21,040 --> 00:07:23,140
So that is the final code.

77
00:07:24,370 --> 00:07:26,620
Thank you for falling, and I'll talk to you later.

78
00:07:26,770 --> 00:07:26,950
Sue.

