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

前端 未结 2 415
执笔经年
执笔经年 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:03

    1. What's the type of a return value in read() function?

    You mean the method read of type file. The command help(file.read) gives:

    read([size]) -> read at most size bytes, returned as a string.

    If the size argument is negative or omitted, read until EOF is reached. Notice that when in non-blocking mode, less data than what was requested may be returned, even if no size parameter was given.


    1. How can I get the first character in a string or array?

    Just like you did, [0].

提交回复
热议问题