一 概念
A F.seek(偏移量, whence=相对位置)
偏移量
大于0的数代表向文件末尾方向移动的字节数
小于0的数代表向文件头方向中移动的字节数
相对位置
0 代表从文件头开始偏移
1 代表从文件当前读写位置开始偏移
2 代表从文件尾开始偏移
B tell函数能够返回指针在文件中的位置。
二 实例解析
file_name = "test1.txt" fp = open(file_name, "r",encoding='utf8') print("point is ", fp.tell()) str = fp.read(18) # 见说明1 print("read data is ", str) print("now position is ", fp.tell()) fp.seek(9,0) print("fp.seek(9,0) ow position is: ", fp.tell()) str=fp.readline() # 见说明4 print("fp.readline() read data is ", str) print("now point is", fp.tell())
|
作者:虚生 出处:https://www.cnblogs.com/dylancao/ 以音频和传感器算法为核心的智能可穿戴产品解决方案提供商 ,提供可穿戴智能软硬件解决方案的设计,开发和咨询服务。 勾搭热线:邮箱:1173496664@qq.com weixin:18019245820 市场技术对接群:347609188 |
|
浙公网安备 33010602011771号