Thuta Learning
ရှာဖွေရန်
IntermediateProgrammingbeginner

Python Write/Create Files

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဖိုင်တစ်ခုထဲကို ရေးဖို့အတွက် 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.
Python Write/Create Files | Thuta Learning