从文件开头删除字节数 [英] Remove number of bytes from beginning of file

查看:130
本文介绍了从文件开头删除字节数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有一种很好的方式在python中完成?



我猜测,简单的方法是用计数器读取字节字节,然后只有在达到256时才开始复制。



我希望为了更优雅的方式。



谢谢。

解决方案

f = open('filename.ext','rb')
f.seek(255)#跳过前255个字节
rest = f.read()#read rest


I want to copy a file without the first 256 bytes.

Is there a nice way to do it in python?

I guessing that the simple way is to read byte-byte with a counter and then start copy only when it get to 256.

I was hoping for more elegant way.

Thanks.

解决方案

f = open('filename.ext', 'rb')
f.seek(255) # skip the first 255 bytes
rest = f.read() # read rest

这篇关于从文件开头删除字节数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆