Hello, everyone.
In this particular session, we would learn about creating a new file on how we will be homophily,
how we can write that will file.
So this particular session is completely devoted on the file handling, which we will be doing so that
you get to know how you can open different files right through a file, read from a file, all those
things.
So the very first thing which I would like to show you is this ID, which is final.
It comes along with the Anakonda installation.
If you want, you can install any other IVI.
There is no restrictions.
Most of the IDs look a little different.
Just same kind of things are present in all the IDs you will have on a video which will just allow you
to type something and get them out footer.
So for example, I can see something like print.
One, two, three, and.
I'll put this in quotes and I can simply run this and it will give me an output indispensably.
In case of Python, we can have an interactive look also with what we can do is we can directly use
this console here so you can increase the size, decrease the size of it.
You can do anything like that.
Now, what I am doing is I am using this control console here so I can do something like twenty three
plus ninety eight and it gives me the desired.
I can declare a variable c E is equal to.
Fifty six, I say be is equal to two, and I can see E plus V, so it gives me the output corresponding
good.
So this is how an interactive console works.
Now, let us do one thing.
Let us first of all, create a file and then we will see how we can work with a particular.
So for this particular session, I have needed a folder, so let me dig this file and see this file
to that particular folder directory so I see you and then I will go to that particular folder of mine
and I will say it was like old.
So.
This is the fault of Bichel and inside, by God, I'm creating.
Read.
Right.
Don't fight, don't fight is the extension for any fight and fight which we will be creating so we can
create a file on this file, will actually help us in running the fight.
So let's create this particular faithful's, so I'll see you.
And this file has been created.
Now, what I can do is I can simply go ahead and start writing and creating my file.
So let's get rid of this first.
Now, there are a few important functions and important things which we do, why the Dingle file and
why the go fight?
So the first thing which we will do is we will open the file object.
Now, how do we open a file object?
We will create a file object, see, and I will say open.
This means that I wanted to open a particular file.
Now, when you see when I write open, it gives me two options.
The one first one is saying F, which means it is a function and the second one is key, which means
that I want to create a fuel, I want to use the existing function open.
So I click on this.
Now, if you see it shows me the difference of of Fatmeh Goes, which are presented this particular
function.
So you can see I can provide the five.
I can give them more.
And different other.
So what I do is there are two important things which I need to hear.
The first thing is the name of the file which I want to open.
So the name of the files see the more one.
Not the I want to create a demo and de.
And I want to open it in a right.
That is, I want to right off right now, there are different modes of operation, so let us read about
different modes forced.
So these are the three types of actions which we can perform when fight, the first action is to open
a file in, read more, read more means that we want to read the fight and then we are leading the fight.
We are not modifying the fight, which means that when I am reading a fight, one of my thinking also
did a fight because we are not making any changes to the fight.
So it will be convenient for both of us.
The second one is W W stands for strike mode is the right.
It means that I want to write a fight, that is, I want to create a new fight.
So I will use W.M. whenever I want to create a new fight.
So that is what we use for writing the fight.
Now, that is the third option of being witches, then we will go right back to pre existing fight.
That is, I don't want to override the five.
I want to add some content to my fight, so that is when the use of pain.
So in this case, when we are trying to write, when we are trying to create a new fight, we will say
w OK, so let's go back.
So this is the fight which I was trying to read and I'll see W.
Which means that I want to light a fire, so I will just run this particular home and when I run this
code, you can see.
Run, and when you run the sport, you don't see anything coming out of you because I have not given
any print statements, that is why I'm not giving any output here.
Let's go back to the follow.
Now, if you go to the folder here, you see that one spying has been created and the deed of Modify
it is also for today and the name is Demo one, and it is a blank slate.
So we have created a blank file here.
Now, let me close this.
And look, we believe this.
OK.
Seems like the file is open in fighting, so let's go back.
Let's do one other thing.
Let's try to read the fight.
OK, so we'll see are.
OK, we'll see.
Ah, and we will change the name to something which is not existing, so we say that more than.
OK, and now we will run this.
So when we run this, you can see that we got this particular error, which is saying that no such file
or directory is formed.
So this means that if you have that file existing Vaillancourt, if the file is not existing and you
run a reed operation, then it will give you an error.
Now, if I again go to the demo to change it to Demo one and I will again read the fighting.
Now in this case, the file is existing.
You can see the demo.
One file is already present here.
So we will run this and now you can see that.
Here you can see that the cell was run.
Now, let us see a few more options which are present here.
So the first option which I have is I can check if the mode in which a file is open.
OK, so how we can do this?
We would save print.
And inside Prince, we will see which is the final object.
And with defy logic, we use a lot of freedom and quality attribute, which is more.
So each file object will have some functions and some attributes associated with it.
So the flip side, which is associated is Cold War.
And when I use this particular more.
I can see the mode in which this is running, so let me do one thing, I need a screen here.
I see mode, so this show me that this is the mode in which the file is running.
Let me add a few more lines of code, so this is what the next what we have is readable so we can check
if a file is readable in nature or not, so we can save the.
And this is the function for the book.
Similarly, when James is to read.
Is readable.
OK, next is.
Will change this to Rightmove.
And this would also change to.
Right in the.
So for now, let's run only this much and we'll run this.
So this is giving an error that.
We have this move, this is if not more.
Read, this is read.
Now let's run it again.
So now you can see this is the output which we get.
What is the output?
It says the move is ah, that is the mode in which we open the file that we are opening the file in
the read.
Next, when we are opening the filing, read more.
That means that this file should be readable in nature.
I can easily read this.
So for this it is showing for readability, showing on Sarastro and for you don't rideable.
It is showing false, which means that I can override this file as of now.
OK, now.
Next thing what we can do is next, let us open this file in right now.
OK, this we have seen for more.
So now let's read this in a right more.
So let me just copy this.
And let me comment this also.
So I just commend the South for this here.
And I'll post it here again.
And let me open this file in right now.
So please know that this particular entire thing, this is a comment, this is basically a string,
so it will act as a comment here so you can use this as a common goal.
So when you will be running this particular find, what you can do is you can just remove these goods
and it will change this into a comment on the comment so you can use it that way.
So I'll open this in a right mood, I'm opening this fight in the right.
So now what I'm trying to do here is when I'm opening this violent mood, I want to write something
to this particular file.
So let me write something.
So let's see if you don't write this will actually write to my afine.
So if you don't right, and inside this, what do I want, right?
I want to write a the new line, so I use the passion for new life and I want to write.
Hello.
Well, that should be the first word, hello, world, and I want to give zation again so I won't be
joining the line.
So this is what we have here.
OK, so now what I can do is I can simply run this.
So when I ran this, it gives me the output that the final mode is like readability is false, right?
Well, it's true.
Now, let's go back to the file again and let's see what happened to a file.
So this is a file.
And I opened this file on.
Nothing really happened to it.
Let's go back and see what happened here.
This is them on board the floor right now.
We have written to this file, but we have not seen that changes.
When will this change?
We see when we close the fight.
So we will close the final.
OK, so we can see if you don't close, this will close my fight.
So what we do, we open the fight.
So what is the process?
The process is.
You will open a file that is the first step, second step, you will write in the file and third step
you will close the fight.
These are the three steps that you will be having.
So let me run this now.
And I'll go back, I'm here again, I will go to this, and now it is showing see, it is also showing
the slashing that is next line, which I have given them.
Now I bouba.
So this is our fight.
So now what we will do is we have returned to this fight.
Now here I am able to write only one line now like this.
I want to write multiple lines.
What I can do is I can give more accurate, Heidi.
This is Second-line.
This is called lying.
And I can run this.
And I think that and this will run I go back to my demo when I close this and go back to this folder,
and here you can see that the line has been updated.
So what we have done is we have successfully written the word fight.
They have successfully turned into a fire, but still there is something missing.
I am able to write to my fire, but I'm able to write to that fire only once.
If I tried to write on top of it again.
See, we tried this again, I do another I tried.
And I see.
Hello again.
And I did give us a potato here again.
And you give a lot of thought and give us slashing, so this will show that I have changed the line
again, so now I will again see a shift in the.
And I go back to my follow.
Inside with that, I go to them will one, and you can see that it has five.
OK, so I can simply use the right function to write different lines of code to my vehicle.
OK, now let's try some more thing.
Now, let me go back now, I have done this, I have done this once.
Now, if let me make some changes, OK?
Now, after running this.
Let me comment this out again.
Let me get my daughter.
OK.
I open this file, I have done this illegally, Ecuador three.
And I'll read something else here.
So now this time, let's write.
Adding new lines.
So let us see, does it I've new line here to are all fine.
So let's save this, let's run this and we go back, we go to this, and now what we have written earlier
has completely gone away.
So we have lost what we had.
But again, so this is what right does.
Right will allow you to make changes to the fight, but it will also override the fire when you know
the same thing again.
So if I want to write the will file again and again after one thread is closed, then what I will have
to do is I even have to obtain the Google fight so I can operate on my file like this.
I will have to open to my file to do it again and again.
OK, so let us try to do that, but first, let's discuss about another concept which is presented by.
So we closed this file again and we go back.
So you can see that it has been defeated.
Now let us see one more concept that would destroy planes.
So we aim for the first function, which we have is right on.
The function that we have is right lines.
So let's get this.
So what will happen, they will try to fight this, right will again try to define.
Now, this is the next one, left and right lines.
So now this will guidelines.
So what I can do is I can add more detailed work, so there has to be an.
So this is right lines.
And I have a lot of data here, so let's see what happens now.
And let me add another red line.
So let me give the straight lines only.
OK, and now let's run and see what happened.
So I say control, as I say, finger to run this and I go back to.
My file again, and you can see that it has done what I have instructed to do, I have got Diavik new
lines, I've got the HelloWallet, I've got the next one.
So I've got all the.
Data, which I have, I did my flight.
Now, let's go ahead and try to think on how we can I think from let us say we have some kind of a breather
or legacy.
We have some other stories point.
We do not always have details given to it by the streams.
We may have the day the in a particular list or some other data structure.
So for that, we can use right lines.
OK, so let us get this, so let me get my stuff if you don't open.
And I know this.
And I was.
Go beyond a common diable one.
And look and see if we're going to open.
Now, this time, what I want to do is.
I want to create something, so let's say my.
Data.
And in my data, I have.
Let me give a list, so let's give a list of different strings so we can work this one, we need two
different strings.
So we have this.
And.
That's hippopotami here.
Will my here?
So we have one.
Do.
And three strings in this one.
Now, latest news.
Another thing, so let us use don't, right, straightforward.
Let's see if we can do this with effort, all right.
And we give my daughter.
OK, and we are doing it for post.
Now, I will run this.
So here you get an error saying that the argument must be string model.
So this means that when I use it for Lord right, it is expecting a string and it will not work on the
list.
So now let us try the same thing.
With a four door, bright lights.
OK, now let me run this.
So let me get back.
Openly one.
And here you can see that it has taken the data from the list and did it way.
So now you can you know, if you think that is the first thing that we have three modes, the first
mode is read, then right then up.
And we have two more modes that is read.
Vanity, right.
Vanity and the appen vanity.
So these virginities ones, these are basically for some other data, talk to some of the fight.
So in case you have to explain, you can simply use a read, write nothing.
But in case you are working on some other file, you can you should use a right vanity and like a read
binary.
So instead of writing on, you will be writing or B the.
So this is what we can do out of it.
The next thing is let's use a law to write this.
So what we can do is we can simply use a loop to write the data using the right option.
So what we can do is instead of doing this entire thing.
We can just do something like this.
And.
Instead of doing this, you can say you can get this, you can save for lying in my data.
If all right.
Nine.
Now, what this does is it will be played on top of my data, the list, and it will write the data
to my file line by line for them, one line by line.
OK, so let me use if I do them so that you don't get confused which file we are writing.
And also I just see this and run this.
I get back.
This is my.
This is then what do I hear the data has been.
Right now, the next thing which we have.
Is the use of the Abang property, though, so a penguin just walking the same way.
So let me get back here.
Get this.
Flows this.
But this year and inside them, we'll go and change it to a fan and I'll add something more to it so
that you'll get to know where we have changed.
So I'll add one more string using a pen now.
So this will show that we are using a pen here.
So we are writing to it.
And then just run this and I'll go back.
This is my Nemoto.
So you can see this, it has been delayed just along with it, so it has added the data to the file,
which was already existing.
Everything is remains just the same.
You can use.
Right, and write lines in the same way, the way we were using it with the like five.
Now, below, what we have done is writing to a fire or a pending bullfight.
Now, these are a few things which you will be doing once you have read the data, inworld on the data.
So the very first thing that you will be doing is reading the fight.
So let us see how we can actually read from the fight.
So to read from a file, we have three functions, which will be the first function will be read next,
will be read in line and the third one will be read the lines.
OK, so this is the demo to files, and you can see this is the data which is already present here.
I just put in a you.
And I see this fight and I close this one, I go by and this is the actual base where I was.
Now I coming this.
Well, the people I know, again, I will read my later.
So how can I be my little also for reading the dialogue to open the filing read, so I say.
I don't need this now.
So you get rid of this.
Now I want to read the data.
So what I will do is I get rid of this also for now.
So we will simply read it for me and I will not give anything here.
OK.
And then I was losing.
Now I want to bring those.
So let me get this data into the data and I'll print data.
Or let's bring in later.
To show that we have the president after closing the files is going to bring.
The.
So now I run this CNN on this, you can see I was able to successfully lead the fight and now I have
read all the lines in the Firebrace.
Now, it is very convenient if I want to read all the lines of the data, but in case I don't want to
read all of the lines, but only a few lines or only lines, one by one.
In that case, what we can do is we can use the line.
So let us see how we can do that.
So I just coming this out again, I get this all.
And let me tell you, the space and the.
Based appeal now.
We see.
What do we want to do?
We have open the file in the.
Now, next, what we want to do is we want to read the lines of says simply.
Ferenc.
If you don't need.
And get rid of this.
Let me do this.
Multiple times.
OK, so let's run this.
What this does is it basically got the data, so it read the first line.
This is the first line.
This is the same second line for line and footling it read all those things.
So let me just point this out so that you will see what it has been doing.
There is a.
So here this is the blunt language is the first line is blan.
This is the second and the fourth line, which is hello.
This is the second, first and third line.
And this is all four lines plus four lines.
So you can read all the lines one by one like this, so if I keep adding this, it will probably print
all the lines which are available.
So it has done the same.
OK, now let's say we have the leg exhaust, all the number of lines here.
So I'm sure that my fire did not contain these many number of lines and none will run this again, so
it gave me a blank space.
So it will continue to read even though there is no legal presence.
OK, so we need to have some mechanism by which we can stop it so you can basically check how many lines
are present and then you can run this red line on top of.
So a more convenient way would be what you can do is you can use read the lines.
So what will read line do?
Red line will again help you to read the details using the lines so I can simply say these lines and
I can get rid of this entire thing.
Lycan.
Bring this so here you can see that it has read the line and it has also read.
These datapoints, these next line present here.
Now, one more thing to notice here is when we used Reline.
It red line one by one.
It rented one line, everything.
And when you will read lines, it gave me back a list containing all the lines in separating this.
So this is how we can actually get the number of lines.
So what I can simply do is I can get Dehlin.
Audrey realigns.
And I have done this so you can see that there are global age lines and then I can read line or I can
use this read lines and then get the data in to let us see.
Data.
And I'll get rid of this and then from Dubai, again, simply say bring.
Data on the index see five.
And this is one see?
Eight is the eighth one.
Now, this does not exist seven.
It shows the seventh one.
So this is how we can run this.
OK, so this is all we can read and write data from a file and.
Read the dull accordingly.
OK, now one more thing, what we can do is we can use the for loop to read this particular date on
weekends and use the.
Makes sense for that, so we can simply say we can simply create a volume and we can use driveline.
So what we can do is.
We can simply say.
For.
You in range, say seven.
I want to bring.
And for the nine.
And so it will be each and every line, one by one.
So this is how you can easily read the files, you can easily read and write text files now how we can
read and write.
Oh, yes, we fight.
So we will be using CSFI files very openly.
Then we will be working with the delphiniums.
So we will be reading files and writing files for the need of names itself.
So let us go ahead and have a look at that as well.
OK, to read and specify what we will be doing so we can do it very simplistic way, using the binders,
libraries or what we will do is we will import Palm Desert Speedie.
The next thing which we will be doing is we will be.
Getting the part of the fight now, we already have a fight present at the store, so I will use the
same.
So I will use the same file from my desktop, so I give the part, so say.
If that is equal to and if I fired you, so I will be giving the Viva.
So my fight is residing at one mine next on Larry King Live divining, so let me see what the filename
is.
So the filename is by data, the CSP.
Now, this is my filing now.
How do I actually read from this, so I will be reading this file into a detail frame.
So I said this is equal to 50 letters from the of Dot V.
Underscore CSB now.
There are several other file extensions also present.
So for them, for all of them, there is a bond US function which will be available.
You can go and search for based on which I would find that you have.
So I have a reason.
So I'm using CSFI.
NTSB is the most mostly used one.
So you will be facing kesby mostly.
So I'm using the PSV and I give the ground races on inside this.
I will give the.
But so the effort.
And along with it, I mean, we don't give a delimiter, so let me just do it this way and how I see
the data is in India not.
Hey, you see the little non-liquid on this.
Now, here you see that the CSP file is having this single column and is giving me a single column,
but I was not expecting to get a single column.
I was actually expecting one, two, three, four columns which are separated by this fight.
So what do I need?
Give us a breather here, because these three fires usually have come as a separate.
But this is an exception piece here.
I have five thousand separate, so I will have to tell the finders.
I believe that this is not a separate other SIPRI that is in the fire.
So what I do is simply say Delimiter and I'll give the delimiter, which is the fire, and then I will
run this again.
So now it will understand that this is the.
The Bible is there for them in two different columns and make this readable in nature.
So this is actually how we will be creating our.
Reading the CSB files and this is all you will read, any spoofy.
Now, that is another thing, what you can do.
You can also lead this fight.
So let's say you have some data said you read the data, said you did your parents formations, and
then you did a modern brain.
The more the and you make some predictions, you made some predictions, and now you want to export
those predictions into this week.
So how would you do that?
So for doing that, we have another function.
So what does that function?
The function is.
And we'll see.
So what we do, we will simply say the data of remains, will we say the door to see us?
And we give the data from the name of the five to one.
So let us say new.
Fine.
Thoughts and ideas run this night on this, I don't get anything, you know, I can simply go to the
flowback.
And this is my new FYI.
And when I will open this.
It will give the pilots it.
So here you can see that this is the damage has been exposed, so you can easily see that the data has
been exploded and the file the tab name has also been given us new.
So this is a very simple example of how we can use kespin right ASV.
Similarly, you can use any other function.
For example, reading and writing, Excel file on file exemplify.
You can write all of those very easily.
Those filmi would be very simple.
It's very similar to this one.
So you can use that.
So this is about reading and writing CSFI, in the next session, we will move towards learning about
Binder's and how we can actually work with those.