1
00:00:00,690 --> 00:00:07,530
In the previous lecture, you learned how to create a text file and still Dumitru in this case, coming

2
00:00:07,530 --> 00:00:13,560
from the random function that represent actual data from a physical sense.

3
00:00:13,620 --> 00:00:21,280
For example, and we are organizing the data in a set of committee limited rooms in this lecture.

4
00:00:21,300 --> 00:00:28,380
I'll show you how easy it is to actually read out the data stored in a text file on the speaker to flash

5
00:00:28,680 --> 00:00:30,220
based file system.

6
00:00:30,750 --> 00:00:35,130
Good information here about the various modules and functions that I'm using by this.

7
00:00:35,130 --> 00:00:36,720
You can see it is very simple.

8
00:00:37,110 --> 00:00:43,420
I'm starting the program by creating a variable that holds the filename that of the working with children.

9
00:00:43,440 --> 00:00:46,740
And I've got a variable here just initializing it to one.

10
00:00:46,740 --> 00:00:53,130
And I'm going to use that to keep track of which line after read or my program has read and has printed

11
00:00:53,130 --> 00:00:54,450
out onto the shell.

12
00:00:55,290 --> 00:01:02,790
And then the part that is interesting really is here inside this loop, you know, it's a block of code.

13
00:01:04,860 --> 00:01:06,320
You're going to make a little modification here.

14
00:01:06,330 --> 00:01:10,800
Obviously, I've got it viable, so I don't need to explicitly pull the file name.

15
00:01:10,800 --> 00:01:17,670
So I'm putting the filename variable, which contains a file name and I'm using the R modifier since

16
00:01:17,670 --> 00:01:20,250
I'm going to be reading only from this file.

17
00:01:20,850 --> 00:01:24,000
So got a handle here and then I've got another loop.

18
00:01:25,260 --> 00:01:32,190
So this one takes one line at a time from the file and I've got then a single line object here.

19
00:01:33,000 --> 00:01:40,170
The first thing that I do is to remove any new line special characters.

20
00:01:40,440 --> 00:01:49,230
Usually you'll find those at the end of a line and you can see there is a backslash and special character

21
00:01:49,230 --> 00:01:50,880
at the end of every one of those lines.

22
00:01:51,300 --> 00:01:56,730
And I know that because then I've got the new line where the text of the new row begins.

23
00:01:57,420 --> 00:02:04,260
So because of the processing that I'm doing later, I want to remove this backslash and then I'm using

24
00:02:04,260 --> 00:02:08,340
the R strip or write strip function.

25
00:02:08,610 --> 00:02:12,060
That is part of my code Python as well as C Python.

26
00:02:13,430 --> 00:02:21,000
Then I've got a line without the backslash in special character and I'll use the split function which

27
00:02:21,000 --> 00:02:24,300
looks for comments like these.

28
00:02:25,650 --> 00:02:28,530
And then uses that as the delimiter.

29
00:02:28,710 --> 00:02:36,270
And each one of the items that come in between the commies are stored in an array to this split function,

30
00:02:36,270 --> 00:02:43,250
creates an array where each of the cells of the common delimited line are stored.

31
00:02:44,100 --> 00:02:45,450
And I'm pointing out that line.

32
00:02:45,480 --> 00:02:51,030
You can have a look at it as well before we actually extract this individual components.

33
00:02:52,260 --> 00:02:58,260
Then if the line is not empty, I'm just a little bit of a test here to make sure that there is something

34
00:02:58,260 --> 00:02:58,960
to display.

35
00:02:59,400 --> 00:03:08,640
So if the line is not empty and it's got at least one character using the all then length function to

36
00:03:08,640 --> 00:03:16,290
check how many characters in a line, and I'm creating a text variable again, I'm using the format

37
00:03:16,380 --> 00:03:19,890
function and I've got my placeholders here.

38
00:03:20,940 --> 00:03:21,900
A bit of text.

39
00:03:22,590 --> 00:03:28,410
You can see I've got a carriage return here or a new line, I should say, a new line, special character.

40
00:03:28,830 --> 00:03:35,970
And then I'm putting the temperature in place, holder humidity in its place, holder, etc. pressure.

41
00:03:36,600 --> 00:03:44,910
And I'm extracting each of the items in the cell by using the regular cell notation.

42
00:03:44,910 --> 00:03:53,790
So Index zero is where I store temperature, index one in the race, a store the humidity and index

43
00:03:53,790 --> 00:04:02,040
two is where store the pressure and finally in line for a do I just print out this string variable and

44
00:04:02,190 --> 00:04:05,820
increase the line number by one.

45
00:04:06,540 --> 00:04:11,750
Once I go through all of the lines and I'm finished with a file, I just close the file and the chip

46
00:04:11,760 --> 00:04:12,690
program finishes.

47
00:04:14,010 --> 00:04:19,990
So I'm going to say this script and start making.

48
00:04:24,640 --> 00:04:27,350
So we've got 20 lines here.

49
00:04:28,060 --> 00:04:31,720
So eventually we have 20 rows that appear.

50
00:04:31,870 --> 00:04:38,590
This is what a raw line comes out the see it's file line number nine.

51
00:04:39,040 --> 00:04:39,600
I'm sorry.

52
00:04:41,080 --> 00:04:45,270
This number indicates how many characters are present in this line.

53
00:04:45,640 --> 00:04:49,750
So really, I should say, just fix this really quickly here.

54
00:04:51,640 --> 00:04:56,030
Can cards to denote characters.

55
00:04:56,050 --> 00:05:00,900
So this number indicates how many characters are present in this line.

56
00:05:01,540 --> 00:05:11,230
So bring down the number of characters then the role line as it comes out of the as file and then break

57
00:05:11,230 --> 00:05:17,760
each component apart using this notation here and construct this string.

58
00:05:17,770 --> 00:05:23,920
But I've got highlighted and it's it appears in four different lines, but that's because I've got these

59
00:05:24,910 --> 00:05:29,620
new line special characters inside this string.

60
00:05:30,520 --> 00:05:39,100
And it's a very it's very easy, as he can see, to read data out of a CHB text file for add one more

61
00:05:39,100 --> 00:05:40,840
line just out of curiosity.

62
00:05:42,060 --> 00:05:47,970
Right there say that this live essentially strong again.

63
00:05:50,560 --> 00:05:51,880
And there's like 21.
