fileName = "stuff.txt" #insert file name
file = open(fileName)
#close the file
file.close()
# read, write, close a file
# catch error if raise
try:
file = open("tryCatchFile.txt","w")
file.write("Hello World")
file = open("tryCatchFile.txt", "r")
print(file.read())
except Exception as e:
print(e)
finally:
file.close()
fileObject.close()
with open("sub_ranks.txt", "r+") as f:
for line in f:
...