The following code is for reading contents from a file
handle=open('file','r+') var=handle.read() print var
If you want to read using a single line readline (). If you want to read all the lines in a file, readlines () are also used.
The following code to write content to a file
handle1=open('file.txt','r+') handle1.write("I AM NEW FILE") handle1.close()
source share