The following built-in functions of Python supports Files I/O operations,
Syntax: file_object=open(file_name, access_mode,[ buffering]) where access_mode may be read, write and append as well as buffering may be set as 0 ( no buffering) and 1(line buffering).
Syntax: file_object.read([count]) – The count parameter indicates the number of bytes that used to read from the existing opened file. The count is optional and if it is undefined then full contents up to end-of-the-file would read.
# Open a file in writing and reading mode
fo = open("abc.txt", "w+")
print ("Name of the file: ", fo.name)
print ("Closed or not : ", fo.closed)
print ("Opening mode : ", fo.mode)
#writing string into the file
fo.write( "Python is an interesting programming.\nIt has various features...great!!\n")
#close the file
#open the file agin in reading mode
fo = open("abc.txt", "r")
#reading 10 bytes from file into st
st = fo.read(10)
print ("Read String is : ", st)
# Check current position of the file
pos = fo.tell()
print ("Current file position : ", pos)
# Reposition pointer at the beginning of the file
pos = fo.seek(0, 0)
#reading full file into st1
st1 = fo.read()
print ("Again read String is : ", st1)
# Close opened file
Name of the file: abc.txt
Closed or not : False
Opening mode : w+
Read String is : Python is
Current file position : 10
Again read String is : Python is an interesting programming.
It has various features...great!!