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

Python Read Files

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

ဖိုင်တစ်ခုကို ဖတ်ဖို့အတွက် mode "r" နဲ့ open() ကိုသုံးပါတယ်။

read(): content အားလုံးကို ဖတ်

readline(): တစ်ကြောင်းချင်းစီ ဖတ်

python
# First, create a file to read
with open("readme.txt", "w") as f:
    f.write("First line.\nSecond line.")

# Now, read the file
with open("readme.txt", "r") as f:
    content = f.read()
    print(content)
You should see
First line. Second line.
Python Read Files | Thuta Learning