python文件seek函数,Python 文件操作seek()函数
函數(shù)語法
seek(offset, whence=0, /)
函數(shù)說明
Change the stream position to the given byte offset.The offset is?interpreted relative to the position indicated by whence.
參數(shù)說明
offset代表移動(dòng)的字節(jié)偏移量
whence代表移動(dòng)的起始位置,缺省為0
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative
注:當(dāng)未使用二進(jìn)制格式打開文件時(shí),從當(dāng)前位置或文件尾進(jìn)行偏移會(huì)報(bào)“io.UnsupportedOperation: can‘t do nonzero cur-relative seeks”錯(cuò)誤,把文件打開方式加上“b”即可。
示例:
f.seek(4,0) #從開頭位置向后偏移4字節(jié)
f.seek(3,1) #從當(dāng)前位置向后偏移3字節(jié)
f.seek(-3,2) #從結(jié)尾位置向前偏移3字節(jié)
總結(jié)
以上是生活随笔為你收集整理的python文件seek函数,Python 文件操作seek()函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PUCCH(2)格式与DTX检测(源于5
- 下一篇: 微众银行七年,从拓荒者到深耕者