![](/img/trans.png)
[英]How can I remove a specific number of bytes from the beginning and end of a file using python?
[英]How can I get open() to skip bytes at the beginning of a binary file?
我想打開使用 Python 3.5 編寫為二進制文件的時間序列數據。
這是我到目前為止編寫的腳本:
filename = 'dummy.ats'
file = open(filename, 'rb')
二進制文件以我想跳過的 1024 字節的頭開始。 我怎樣才能修改我的腳本來做到這一點?
函數seek()
允許您將閱讀光標移動到文件中所需的位置(當您閱讀某些內容時,該光標會自動向前移動)。
它的工作原理如下:
file.seek(how many positions you will move[,0 or 1 or 2])
( [] <- 表示可選)
os.SEEK_SET
):表示您的參考點是文件的開頭os.SEEK_CUR
):表示您的參考點是當前文件位置os.SEEK_END
):表示您的參考點是文件的結尾但是你可以省略它,它會是 0
filename = 'dummy.ats'
file = open(filename, 'rb')
file.seek(2)
如果您從那里閱讀,您將從第二個字符開始閱讀
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.