I found this solution from stackoverflow but will i have to add this piece of code every time i write a code to perform read/write operations. Or is there any long term solution available for this ?
import os
path = "E:\Python\learn"
os.chdir(path)
f = open('text.txt')
data = f.read()
print(data)
f.close()
I think you need a way to read same file multiple times in your python code. Use file.seek() to jump to a specific position in a file. However, think about whether it is really necessary to go through the file again. An Example for file.seek:
Incase you want to re-iterate the file second time and don't want to open the file again, you can follow this syntax: