Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธี Append (ต่อท้าย) ไฟล์ใน Python

เปิดไฟล์ mode 'a' (append) จะตั้ง pointer ที่ท้ายไฟล์:

f = open('my_file.txt', 'a')
file_content = f.read()
f.write('Hello World')
f.close()

จะเพิ่ม "Hello World" ท้ายไฟล์