IMPLEMENTATION OF 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 sessions we have seen the files concept so I hope you open a file how to create a file and how to close your file and the what are the different access modes to open a file and what are the reading operations and writing operations so let us see everything by implementing a simple programs right so so main advantage of file is to save the output right see let us write the program so in order to implement this file also that can be done by using one file point there let us take f1 as a file pointer f1 is equal to open some hello dot txt is a file name I am opening in write mode hello dot txt in write mode so after implementing this one one I mean the text file has been created and the file pointer points at the beginning of the file now start writing f1 dot write write the content so f 1 dot right this right function will take only one argument that is a string so whatever the string we have to enter into a file right into a file that must be returned here so after executing this the file I mean the data has been written now close the file f1 dot close so let us execute and check whether the file has been created with a given text or not excuse me hello dot py sorry I'll 1 dot py now we'll execute this one run this file so nothing has been printed but we have to check whether the file has been created or not so now the question is where the file has been created so in order to check whether the file has been created or not just to import the air voice and right sorry where's dot get CWD so if you implement this one we can get the current working directory that means where these files has been saved so G in G Python programs now our file has been created in that particular location let us check in G there is a folder called time programs C here we can find the text file hello C hello dot txt welcome to Python programming just know we have created the file right now let us redefine now again open the file in the read more next f1 dot and read so it will read just it will read the data from the file and it will be holded in the buffer if you write the print function it will display on the screen print f1 dot read run this program save so the data has been I mean that the content which we have which is available in that particular file has been printed on the screen welcome to python programming and if you give the argument five so only five characters will be printed hope you understood this one then again if you print f1 dot read of four so well welc whoa ma space t because so after executing the first statement the file pointer is at the sixth position so five positions has been written to the screen and this the file pointer points to this sixth position from the sixth position the four characters will be printed here so unless you close the file the file pointer never goes to the beginning of the file so f1 dot close right now let us see the multiple lines new file f1 is equal to open some M lines dot txt w f1 dot sorry lines is equal to u the list welcome give a /n a new character use Python programming so I have written three statements in a list right now I will write this lines upon not wide lines of lines then f1 dot close and let us execute this one file to execute this one so let us check whether the file has been created with the given text or not if you see here M lines dot txt so three lines has been created so if you observe here the three lines has been created right now let us have read the same data again f1 dot force on f1 is equal to open M lines dot txt read mode f1 dot readline just I am executing the red line f1 dot just I will I will write it in a print so that it will be displayed on the screen so welcome this is the first line so if you implement the same thing so now the file pointer will be in the second line see welcome Python two lines have been printed if you implement this let the lines read lines now everything will be printed welcome Python program the list complete list will be printed right so hope you understood this one now let us try with the append mode if you append one if you open this M line start text in epping 1 append mode and try to write one more line so after executing this one just will check on the program itself my is dot txt so there is the fourth line that is hello so that means in append more the file pointer points at the end of the file and of the content of the file so whenever you are writing the data the data will be appended so without overriding the rule data so the previous data will be remain same and the new data will be appended from the end of that particular file so if you read it one F 1 is equal to open em - dot txt read more print F 1 dot read up on dot close so if you write you can secure this one all the complete content will be displayed on the screen so hope you understood this simple files/programs so rate mode append mode and a write mode and the read read function read line read lines right function and write lines right so if you are having any doubts regarding this files program feel free to post your doubts in the comment section so that I will definitely try to clarify all your doubts and if you really understood my sessions like my sessions share my sessions with your friends and don't forget to subscribe to our Channel so thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 13,353
Rating: 4.9628482 out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, HIGH-LEVEL, LANGUAGE, PYTHON SHELL, PYTHON SCRIPT, BEGINNERS, GUI, GAMING, PYTHON 3.7.0, CASE SENSITIVE, SIMPLE, Python, Python Lists, Python Tuples, Python Sets, Python Data Types, Python for Beginners, 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: 94ZqI4oQNc0
Channel Id: undefined
Length: 11min 37sec (697 seconds)
Published: Fri Oct 19 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.