我有代码:
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!")
为什么它不起作用?我没有收到任何错误,此后文件内容变得混乱,我做错了什么?
我有代码:
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!")
为什么它不起作用?我没有收到任何错误,此后文件内容变得混乱,我做错了什么?