ဖိုင်တစ်ခုထဲကို ရေးဖို့အတွက် mode "w" (overwrite) သို့မဟုတ် "a" (append) ကိုသုံးပါတယ်။
python
# "w" will overwrite the file
with open("log.txt", "w") as f:
f.write("Log started.\n")
# "a" will append to the end
with open("log.txt", "a") as f:
f.write("New entry added.")
# Read the final file to verify
with open("log.txt", "r") as f:
print(f.read())You should see
Log started. New entry added.