READING & WRITING DATA INTO FILES - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous session we have seen the files concept so how to open a file how to create a file and how what are the different access modes and then we have seen how to close em right so in that we have seen the access mode the majorly three access modes that is a very light and a pen so we can open any file in any one of these access to modes now let us see in this session the reading and writing operations or files right so for reading oppression a file should be opening read more I do operation a fine should be opened in in the right mode or a bit more so in the right mode if I exist content will be overridden so all the previous and they will do overrated fine doesn't exist new file will be key so in this whole same you define exist point the point set end of content even the fine doesn't exist new file will be created so the file can be created in Foods in is a writer effect so after opening the file then we have to perform the reading and writing operations let us see the reading operation or first we will see the writing writing operation so there are two methods what is right and what is right lines my function right lines function right so the very self indicates this right function we write a single line however as write lines function will write the multiple lines see the syntax is so before going to implement these two write lines or write function we have to open the file I will see in the syntax in the previous session five object is equal to open some ABC the txt and in I write more so if you want to write this I mean if you want to write the content into a file how to implement this one by using the file pointer f1 dot right and this will take one argument that is the string so whatever we want to write into the file that should be written as an argument right so a sequel written string it will write the string in their file so stinking seas of alphabets numbers symbols and everything will be comes under this chain right so anything can be retained into a file as a ultimate so I have to pass it an ultimate see example first I will write I will open a file F open it we see dot txt right next f1 dot right so we can we have to write the string directly welcome to so automatically this content will be returning to ABC dot so this is the first I mean in order to write the content of one way so it will not consider the newline character so as if you want to write multiple lines go with this so here also we have to implement this by using the file pointer so high times you have for not write lines so here let us see the example see see yep was not write wines give the list of lives so first of all we have to write the lines in a list and the list should be positive powers as an argument all right let's see example f1 is equal to open UPC dot txt write more next - is equal to and creating a list hello meltem turtle do breathing so here I have written three elements as a strings and these three elements are a list called blends so should we pass these lines to the right man now get right F was not right hands off so this will automatically write all these three lifelines I hope you understood this one okay so these are the two feathers to write the data into a file now let us see the reading operations here similar to the right function the range operations are also three pets and we have to implement this reading operation by means of this five point so first of all in order to read the content of your file we have go over the file in read more so first one is Li function so we have the implement F 1.3 here the ultimate is build positions the 100 it will take it will take it bit positions as an argument so here whatever the bits you have mentioned those bits will be displayed on the screen for example the next is hello welcome and if you are trying to read fine f1 dot read file so this is the content available in yet lessee dot txt so I have opened this ABC dot exe read more and then so whenever you open the file in rate code the file pointer will be and the starting position so you have for not read of 5 that means from the starting position 5 which will be away then it will be displayed on the screen so fine wines will 1 2 3 4 5 so the output for this one is hello and immediately after achieving this one the file pointer will be at this position because already file has been displayed again if you read one more statement like and read find from here itself it will come find some space is also like character 1 2 3 4 so this output is space w/e l see so 1 2 3 4 5 right this will be printed now after executing this one the 5 coin will be yet whoa firefighter will be yet ohh so if you write again the statement afraid of 3 this is you om e so every time the operation is executed the file pointer will be moved towards its right side right so unless you close the close the file and open the file the file pointer design comes to the beginning of the file so here they positions is an optional thing so if you mention here the bit positions that many bit positions will be displayed on if you have not mentioning here if you are still just hiding as F will not create this will return everything all the content of the file hello so this position this will positions is optional so we can specify the positions how many of these characters we need to ring on if you want to read everything just we can ignore this bit position yes we can write a for not really everything will be printed if you should display some remember that many characters will be and the file pointer starts moving from its right from the beginning to its right this is about the raid next and they'd like see the second one is Hagelin so it'll be here there are three ends hello welcome Python programming now if you open this ABC dot X team in Radian mode and if you are trying to read you can paint this red line so whenever we open this file in read mode the file pointer will be at the starting position right starting position so if you improve in this red line the first line in the content of the first line will be displayed so hello will be printed so everything in the first plane everything in the first line so I have to exceed in this one the file pointer moves to the second line because every kind and all the kind of first line is displayed if again if you are implementing this refrain in the same program without closing the file right so if you close your file once and if you open the file automatically in the final point and again points at the beginning so unless you close to find the final point that doesn't changes its position right so here after achieving this first line the profiling pointer will be in the second line so again if you include this red line it will bring welcome now the file pointer moves to the beginning of the third line because second line the complete content of the second line has been printed now saying if you implement the same thing red line once again the third line will be printed but third line will be printed right so read that means three an tagline content of single line so what about the content having in the line that will be printed so this is it doesn't make any argument right it's an argument is it doesn't take any other next to the turnover is sympathy that is flow rate it lines red lines so great lines means leaving the content of all lines so f1 thought red lines so it still multiple ends right so this implementation of this function will return everything hello welcome okay so all the lines will be printed right so hope you understood this one then let us see an example so this we will write a program to write the content into reader content first in order to write the content we need one five point then so first we have to create a file so f1 is equal to open let's take the same file in ABC dot txt all right so in write more that makes a new file will be created so immediately have exuding this one so one file will be created on file will be created with ABC dot txt and the pointer will be at the beginning next f1 dot right welcome to so after doing this now it will be written welcome to now the file pointer points at this position right no you're not close so automatically the file pointer has been closed again open the file pointer in a reboot open the ABC dot txt read more automatically this will be in rain board and the five point and points at this position next so if you write here for not ray it will really everything but it will not be printed on the screen because it will be in buffer so we have to assign a variable and then we can print that variable in so that the content will be displayed on the screen or directly we can call this in the print function so print F 1.3 so far the beginning itself everything will be printed in the output screen everything will be printed so when I come to I thought will be right so hope you understood this one so let us stop here so in this session we have seen the reading and writing operations on files reading or writing data on files so in that we have seen the write function and write lines and read read line and red lines so here the major important thing is the position of the file pointer so unless you close the files are positive the position of the file pointer will never come to the beginning of the frame right so the final point I keep on my executing the statements the final point that also moves from the starting position to the two words it's alright so let us stop here hope you understood this is a simple session so if you are having any doubts regarding this Python programming feel free to post your thoughts in the comment section so that definitely I will try to clarify all your doubts so if you really understood my sessions like my sessions share my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 40,173
Rating: 4.9194632 out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, HIGH-LEVEL, LANGUAGE, PORTABLE, FEATURES, APPLICATIONS, INSTALLATION, INTERPRETER, PYTHON SHELL, PYTHON SCRIPT, INTRODUCTION, BEGINNERS, GUI, GAMING, WEB DESIGNING, PYTHON 3.7.0, PLATFORM INDEPENDENT, CASE SENSITIVE, SIMPLE, files, read mode, write mode, append mode, access modes, read, readline, readlines, write, writelines, operations, reading data, writing data, file open, file close, file create, string, bits, file object, file pointer
Id: FqcjKewJTQ0
Channel Id: undefined
Length: 18min 49sec (1129 seconds)
Published: Thu Oct 18 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.