ဖိုင်တစ်ခုကို ဖတ်ဖို့အတွက် 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.