Posts

Showing posts with the label File Handling

Python3 File Handling

Python  File Handling FILE  I/O          File is a named location on disk to store related information. It is used to store data permanently in a non-volatile memory (eg. hard disk).  Since, random access memory (RAM) is volatile which loses its data when computer is turned off ,we use files for the future use of the data    When we want to read from or write to a file we need to open it first. When we are done, it needs to be closed, so that resources that are tied with the file are freed.  File operation :   1.  Open a file   2.  Read or write(perform operation)   3.  Close the file Opening a File        Python has a built-in function open() to open a file. This function returns a file object, also called a handle, as it is used to read or modify the file accordingly.        #open file in current directory            f=open('example.txt')          we can specify the mode while opening a file. In mode, we specify whether we want to read 'r' , write 'w' or appen