文件的截取:truncate方法 分类: open()文件读写 2014-01-21 18:59 245人阅读 评论(0) 收藏

file的截取:truncate([size]) #原地修改文件

>>> help(f.truncate)
Help on built-in function truncate:

truncate(...)
    truncate([size]) -> None.  Truncate the file to at most size bytes.
    
    Size defaults to the current file position, as returned by tell().
    
    
1.指定size,则将整个file保留size个字符
2.没有指定size,保留文件的字符个数 = tell()方法返回的值。如果f.tell()=0(指针位于文件开头),即保留0个字符,即清空文件内容

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/think1988/p/4627959.html