Basic commands to understand the open command
f = open(“text.ext”) <— default mode is read “r”
f.read()
f.readline()
f.readlines()
Once read, if you need to go back to the beginning of the file : f.seek(X)
output = f.”read.option”()
print(output) = text.ext
f.close()
Now by doing this you don’t need to close the file.
with open(“file.ext”, “r”) as f:
….output = f.”read.option”()
Basic commands for writing files
f = open(“file.ext”, “w”) or with open(“file.ext”, “w”) as f:
….f.write(“blablabla\n”) or f.write(output of a variable)