- open() function opens the file and returns a file object.
- tell() function tells the current cursor position.
- seek() function allows us to change the cursor position.
- close() function closes the file.
- The program will also run perfectly if we don’t close a file. But closing a file is a good practice.
f = open('File1.txt')
print(f"Curser position is - {f.tell()}")
print(f.read())
print(f"Curser position is - {f.tell()}")
print(f"Before seek method, cursor position was at - {f.tell()}")
f.seek(0)
print(f"After seek method, cursor position is at - {f.tell()}")
print(f.read())
f.close()
OUTPUT :
Curser position is - 0
Hey, I'm Sayan Dey.
I'm from Chandannagar.
My emai id is - d.sayan1998@gamil.com.
There's a big pandemic situation in the world. Hope everyone is okay.
Stay at home.
Stay safe.
Use sanitizers.
Use hand gloves.
Use handwashes.
Curser position is - 233
Before seek method, cursor position was at - 233
After seek method, cursor position is at - 0
Hey, I'm Sayan Dey.
I'm from Chandannagar.
My emai id is - d.sayan1998@gamil.com.
There's a big pandemic situation in the world. Hope everyone is okay.
Stay at home.
Stay safe.
Use sanitizers.
Use hand gloves.
Use handwashes.
CONTENT OF MY FILE :
Hey, I’m Sayan Dey.
I’m from Chandannagar.
My emai id is – d.sayan1998@gamil.com.
There’s a big pandemic situation in the world. Hope everyone is okay.
Stay at home.
Stay safe.
Use sanitizers.
Use hand gloves.
Use handwashes.