【发布时间】:2020-04-21 19:12:42
【问题描述】:
我有一个名为 offset 的变量属于 <class 'bytes'>。
我需要找到b/w offset和mapper[hash]的区别,这里mapper[hash]属于<class 'numpy.int64'>。
我的功能如下:
for hash, sid, offset in x:
yield(sid, int(offset) - mapper[hash])
注意:在原始函数中,偏移量没有被强制转换为 int。我故意这样做是为了让他们与众不同。
但这是抛出一个错误说
ValueError: invalid literal for int() with base 10: b'\xf9\x01\x00\x00\x00\x00\x00\x00'
并不奇怪,虽然在调试时我打印了偏移量而不进行类型转换并找到了值 ->
b'\xcb\x10\x00\x00\x00\x00\x00\x00'
b'B\x10\x00\x00\x00\x00\x00\x00'
b'T\x1c\x00\x00\x00\x00\x00\x00'
这个问题有哪些可能的解决方案。
【问题讨论】:
标签: numpy type-conversion python-3.6 literals hashlib