مثال
باز کردن فایل با مُد a برای اضافه کردن محتوا به انتهای فایل و سپس نوشتن یک لیست متن در آن:
f = open("demofile3.txt", "a")
f.writelines(["See  you soon!", "Over and out."])
f.close()
#open  and read the file after the appending:
f = open("demofile3.txt", "r")
x = f.read()
توضیحات
متد writelines() آیتم های لیست ورودی را در فایل می نویسد.
سینتکس
file.writelines(list)
مثال
مانند مثال قبل با این تفاوت که به هر عضو لیست، کاراکتر خط جدید اضافه شده است:
f = open("demofile3.txt", "a")
f.writelines(["\nSee  you soon!", "\nOver and out."])
f.close()
#open  and read the file after the appending:
f = open("demofile3.txt", "r")
x = f.read()
دیدگاهها