Python ဖိုင်ကို truncate() နည်းလမ်း
ဥပမာ
နောက်ဆက်တွဲအတွက် "a" ဖြင့် ဖိုင်ကိုဖွင့်ပါ၊ ထို့နောက် ဖိုင်ကို 20 bytes သို့ ဖြတ်တောက်ပါ-
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()
ဖိုင်ကို ပေးထားသော bytes အရေအတွက်သို့ အရွယ်အစားပြောင်းသည်။
အရွယ်အစားကို မသတ်မှတ်ထားပါက လက်ရှိအနေအထားကို အသုံးပြုပါမည်။
အထားအသို
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. |