最佳答案
我正在尝试用 Python 读取一个 BMP文件,我知道前两个字节 表示 BMP 公司。接下来的4个字节是文件大小。当我执行:
fin = open("hi.bmp", "rb")
firm = fin.read(2)
file_size = int(fin.read(4))
我得到了:
ValueError: int ()的无效字面值以10为基数: ‘ F # x13’
我想要做的是读取这四个字节作为一个整数,但似乎 Python 是读取它们作为字符,并返回一个字符串,这不能转换为一个整数。我怎样才能正确地做到这一点?