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

Python File Handling

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

Python မှာ ဖိုင်တွေကို ဖတ်ခြင်း၊ ရေးခြင်း ပြုလုပ်နိုင်ပါတယ်။ open() function ကိုသုံးပါတယ်။ with statement ကို သုံးတာက ဖိုင်ကို အလိုအလျောက် ပိတ်ပေးတဲ့အတွက် အကောင်းဆုံးဖြစ်ပါတယ်။

"r": Read

"w": Write

"a": Append

python
with open("myfile.txt", "w") as f:
    f.write("Hello, this is a new file.\n")
    f.write("This is the second line.")

print("File 'myfile.txt' has been created.")
You should see
File 'myfile.txt' has been created.
Python File Handling | Thuta Learning