File, read and write operations.
So what is a data file file is a logical unit of related information stored on a Nimda location on disk,
it is used to permanently stored data in a non-volatile memory as example, hard disk.
We can keep our data in different genotypes.
So like the numbers, like your tuples, lists, sits, dictionaries and so on.
But all of them are occupying space in the memory that is REM.
So when the program will get terminated, when my machine will be shut down, in that case, that data
will be lost.
So we are supposed to have some mechanism with the help which we can store our data on to our secondary
storage.
That is a nonvolatile storage.
Let it be hard disk.
So the best means to do that one is through our data files.
So filing is a logical unit of related information stored on a location, on a disk, and it is used
to permanently store data onto a non-volatile memory.
Here it is, our disk as an example.
So since random access memory that is REM is volatile, so it cannot be treated for permanent storage
of data.
When you want to read from or write to a file, we need to open it at first.
Then we are we are done.
And when this one is done, then it needs to be closed so that the resources that are tied with the
file are getting free.
So before reading or writing on the data file, at first we are supposed to open the file in the respective
mode.
Then what about the operations we are supposed to do and get it done and then we shall close the file
so that the allocated resources will be declared as a free so.
Hence, in Python, a file operation takes place in the following sequence that is open a file, read
or write that is a from the respective operation and then close the file.
So there are three steps with the help of which the file handling can be done in Python.
So these are the file python file, Modisane, the first one is are open the file for the reading that
is a by default if we don't mention it will get opened in the army.
That is a read what w open the file for writing creates a new file if it does not exist or truncated
the file if it is existing.
Next one is open.
A file for exclusive creation in the file already exists.
The operation files.
So then is it XML?
In case of a mode open a file that is for appending at the end of the file and without truncating it
creates a new file if it does not exist.
So that is in case of the file is pre existing and then the pre existing file version will get opened
and the new content will be appended back.
If the file is not pre existing then against that, giving them the file get created and that will be
opened.
Next one is to open the file in the text won't be open the file in the binary mode and means open a
file for updating that is reading and writing mode.
So let us go through some examples here.
So if one is going to open employee debt here to see we didn't mention any more, so by default this
armored will be there.
So equivalent to r r r t, what is out there is a read Dixmoor.
You can find this one this r t if two is going to open Pigott GPG R plus B.
So what is the R R stands for this.
This is my read operation.
And what is A B B is that is a binary mod that is read and write in the binary mod.
Next one is the F three that is open.
There is a text in W mode that is a right in the text mod.
So in this way we have given some sample codes to show you that how this mould's can be used while opening
one file.
Closing a file in Biton, so you see, when we are done with the operations to the file, we need to
properly close the file and closing is a file.
Closing a file will free up the resources that were tight with the file as this is done using Python
closed method.
So using this closed method, the file will be closed and the allocated memory space which was allocated
for these files, will be declared as a free space.
Python has a garbage collector to clean up the unrefuted unreferenced objects, but we must not rely
on it to close the file.
So that's why we should close the file ourselves in the coding.
We should not consider the garbage collector will come and it will make all the unreferenced resources
to make them free.
We should not rely on that.
It is our common practice.
It is a good practice for the programmers.
Open the file, do the operations and close it.
So here we are having some examples.
So if it is going to open employed or that encoding is a goal to UTF eight and then perform some operations
file operations, and then if that close to close the file so that they are allocated, resources will
be declared as free.
So in this particular video, we have discussed that how to perform the region.
Right.
Operations on file in case of Python.
That's what watching this video.