पायथन फ़ाइल ट्रंकेट () विधि
उदाहरण
संलग्न करने के लिए फ़ाइल को "ए" के साथ खोलें, फिर फ़ाइल को 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. |