What's the type of read() function's return value?

前端 未结 2 379
执笔经年
执笔经年 2021-01-23 17:23

I wanna read first 188 bytes from a binary file, and check whether the first character is 0x47. Code below:

import os
fp=open(\"try.ts\",\"rb\")
for         


        
2条回答
  •  遥遥无期
    2021-01-23 18:12

    if buf[0]=="\x47":
    IndexError: string index out of range
    

    That means your buf is empty. You overwrote it 100 times in your loop. The file probably doesn't have 18800 bytes in it. At the end of a file read just returns an empty string. Did you mean to put your if inside the for? If so, indent it accordingly.

提交回复
热议问题