How can I get open() to skip bytes at the beginning of a binary file?

后端 未结 1 1523
無奈伤痛
無奈伤痛 2021-01-16 04:27

I would like to open time series data written as a binary file using Python 3.5.

Here is the script that I wrote so far:

filename = \'dummy.ats\'
fi         


        
相关标签:
1条回答
  • 2021-01-16 05:19

    The function seek() allows you to move the reading cursor where you want in your file (this cursor automatically moves forward when you read something).

    It works like :

    file.seek(how many positions you will move[,0 or 1 or 2])
    

    ( [] <- means optional)

    • 0 (or os.SEEK_SET): means your reference point is the beginning of the file
    • 1 (or os.SEEK_CUR): means your reference point is the current file position
    • 2 (or os.SEEK_END): means your reference point is the end of the file

    But you can omit it and it'll be 0

    filename = 'dummy.ats'
    file = open(filename, 'rb')
    file.seek(2)
    

    if you read from there, you'll read from the 2nd character

    0 讨论(0)
提交回复
热议问题