In the previous lecture, you learned how to create a text file and still Dumitru in this case, coming
from the random function that represent actual data from a physical sense.
For example, and we are organizing the data in a set of committee limited rooms in this lecture.
I'll show you how easy it is to actually read out the data stored in a text file on the speaker to flash
based file system.
Good information here about the various modules and functions that I'm using by this.
You can see it is very simple.
I'm starting the program by creating a variable that holds the filename that of the working with children.
And I've got a variable here just initializing it to one.
And I'm going to use that to keep track of which line after read or my program has read and has printed
out onto the shell.
And then the part that is interesting really is here inside this loop, you know, it's a block of code.
You're going to make a little modification here.
Obviously, I've got it viable, so I don't need to explicitly pull the file name.
So I'm putting the filename variable, which contains a file name and I'm using the R modifier since
I'm going to be reading only from this file.
So got a handle here and then I've got another loop.
So this one takes one line at a time from the file and I've got then a single line object here.
The first thing that I do is to remove any new line special characters.
Usually you'll find those at the end of a line and you can see there is a backslash and special character
at the end of every one of those lines.
And I know that because then I've got the new line where the text of the new row begins.
So because of the processing that I'm doing later, I want to remove this backslash and then I'm using
the R strip or write strip function.
That is part of my code Python as well as C Python.
Then I've got a line without the backslash in special character and I'll use the split function which
looks for comments like these.
And then uses that as the delimiter.
And each one of the items that come in between the commies are stored in an array to this split function,
creates an array where each of the cells of the common delimited line are stored.
And I'm pointing out that line.
You can have a look at it as well before we actually extract this individual components.
Then if the line is not empty, I'm just a little bit of a test here to make sure that there is something
to display.
So if the line is not empty and it's got at least one character using the all then length function to
check how many characters in a line, and I'm creating a text variable again, I'm using the format
function and I've got my placeholders here.
A bit of text.
You can see I've got a carriage return here or a new line, I should say, a new line, special character.
And then I'm putting the temperature in place, holder humidity in its place, holder, etc. pressure.
And I'm extracting each of the items in the cell by using the regular cell notation.
So Index zero is where I store temperature, index one in the race, a store the humidity and index
two is where store the pressure and finally in line for a do I just print out this string variable and
increase the line number by one.
Once I go through all of the lines and I'm finished with a file, I just close the file and the chip
program finishes.
So I'm going to say this script and start making.
So we've got 20 lines here.
So eventually we have 20 rows that appear.
This is what a raw line comes out the see it's file line number nine.
I'm sorry.
This number indicates how many characters are present in this line.
So really, I should say, just fix this really quickly here.
Can cards to denote characters.
So this number indicates how many characters are present in this line.
So bring down the number of characters then the role line as it comes out of the as file and then break
each component apart using this notation here and construct this string.
But I've got highlighted and it's it appears in four different lines, but that's because I've got these
new line special characters inside this string.
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
line just out of curiosity.
Right there say that this live essentially strong again.
And there's like 21.