从任意位置读取任意长度数据
def funn(location,length):
path = os.path.join(os.path.abspath(os.path.dirname(__file__) + os.path.sep + ".."), "xxxx", "xxxx")
filedir = os.path.join(path,filename)
try:
with open(filedir, 'r') as fs:
fs.seek(location, 1) # location为 开始的偏移量,也就是代表需要移动偏移的字节数
databuffer = fs.read(length)
except Exception as E:
log.error(E.message)
按顺序读取文件数据
class test(object):
keeplocation = "" #全局保存读取文件的位置,循环调用funn函数,可以按顺序不断读取文件数据
def funn(self,length):
path = os.path.join(os.path.

本文介绍如何在Python中实现从文件的任意位置开始,读取特定长度的数据,这对于处理大文件或者需要按需获取数据的场景非常有用。
最低0.47元/天 解锁文章
806

被折叠的 条评论
为什么被折叠?



