I have the code:
filename = "C:/users/patrik/documents/mypython.txt"
with open(filename) as f:
if f.readlines()[0] == "patrik's file": #first line
f.write("This file has been read by patrik!")
Why does it not work? I’m not receiving any errors, and the file content gets messy after this, what am I doing wrong?
To perform both read and write operations on your file you can choose one of these modes:
'r+':'a+':Note that
fileis a builtin function in python, so you should not use it as a variable name