طريقة اقتطاع ملف بايثون ()
مثال
افتح الملف بعلامة "a" للإلحاق ، ثم اقتطع الملف إلى 20 بايت:
f = open("demofile2.txt", "a")
f.truncate(20)
f.close()
#open
and read the file after the truncate:
f = open("demofile2.txt", "r")
print(f.read())
التعريف والاستخدام
تقوم truncate()
الطريقة بتغيير حجم الملف إلى العدد المحدد من البايت.
إذا لم يتم تحديد الحجم ، فسيتم استخدام الموضع الحالي.
بناء الجملة
file.truncate(size)
قيمه المعامل
Parameter | Description |
---|---|
size | Optional. The size of the file (in bytes) after the truncate. Default None, which means the current file stream position. |