从特定字节读取pdf文件到文件末尾

时间:2014-08-27 21:38:43

标签: python pdf offset

我使用下面的代码从文件的开头读到字节89,但是如何从字节89读到文件的末尾?

with open('hello-world.pdf','rb') as input_data:
    ima = input_data.read(89)
    print ima

3 个答案:

答案 0 :(得分:3)

.seek()文件操作设置文件的当前位置。

with open('hello-world.pdf','rb') as input_data:
    input_data.seek(89)      # Move to byte #89, i.e. skip first 89 bytes
    ima = input_data.read()  # Read all bytes from 89 to end of file
    print ima

答案 1 :(得分:2)

您可以访问字节89以使用此简单代码结束,只需使用list即可访问它:

with open('hello-world.pdf','rb') as input_data:
    ima = list(input_data.read())
    print ima[89:]

答案 2 :(得分:-2)

aFH = open( 'hello-world.pdf', 'rb' )              # .GET aFileHANDLE
aFH.seek( 89, 0 )                                  # .MOV aReadPOINTER
ima = aFH.read( ... )                              # .GET ...