成免费的crm,久久国产精品新农夫导航新妓网,恋夜秀场全部视频安卓手机,女校花强奷在线播放A级

Python os.ftruncate() 方法

python os.ftruncate() 方法

python os 文件/目錄方法python os 文件/目錄方法

os.ftruncate() 裁剪文件描述符fd對應(yīng)的文件, 它最大不能超過文件大小。

unix, windows上可用。

 

語法

ftruncate()方法語法格式如下:

os.ftruncate(fd, length)

 

參數(shù)

  • fd -- 文件的描述符。
  • length -- 要裁剪文件大小。

 

返回值

該方法沒有返回值。

 

實例

以下實例演示了 ftruncate() 方法的使用:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
# 打開文件
fd = os.open( "foo.txt", os.o_rdwr|os.o_creat )
# 寫入字符串
os.write(fd, "this is test - this is test")
# 使用 ftruncate() 方法
os.ftruncate(fd, 10)
# 讀取內(nèi)容
os.lseek(fd, 0, 0)
str = os.read(fd, 100)
print "讀取的字符串是 : ", str
# 關(guān)閉文件
os.close( fd)
print "關(guān)閉文件成功!!"

執(zhí)行以上程序輸出結(jié)果為:

讀取的字符串是 :  this is te
關(guān)閉文件成功!!

python os 文件/目錄方法python os 文件/目錄方法

下一節(jié):python os.getcwd() 方法

python 教程

相關(guān)文章