Fork me on GitHub

一 概念
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())
复制代码

 

posted on   虚生  阅读(42)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
历史上的今天:
2023-04-18 stm32文件系统读写操作调试总结
2023-04-18 基于ads1299的可穿戴脑电信号采集之性能调试总结
点击右上角即可分享
微信分享提示