## 修改文件ide
with open("test.txt", "w+") as f:rem
f.write("I am a dba.\n")it
f.write("I am a boy.\n")class
f.seek(0)test
print(f.read())developer
f = open("test.txt", "r")db
with open("test.txt.bak", "w+") as f_n:di
for l in f:文件
l = l.replace("dba", "developer") # 對指定內容就行替換修改view
f_n.write(l)
f_n.seek(0)
print(f_n.read())
f.close()
if "test.txt" in os.listdir("."):
os.remove("test.txt")
os.rename("test.txt.bak", "test.txt")