【发布时间】:2015-01-29 08:44:05
【问题描述】:
请帮忙,这让我发疯了。
def get_pinstatus(*args):
ser.write("p".encode())
time.sleep(1) # wait for buffer to fill up
# for i in range (16):
value= ser.read(1)
new_value = int.from_bytes(value, byteorder='big')
这是相当简单的代码,它将从串行读取 16 个单独的字节,我需要将每个字节转换为 8 位 int。如果我在 python 命令行中键入最后 4 条语句,它会完美运行,只是在函数中时不行。 无论我如何格式化代码,我总是收到以下错误:
new_value = int.from_bytes(value, byteorder='big')
AtrributeError: 'NoneType' object has no attribute 'from_bytes'
【问题讨论】:
-
或许可以考虑
struct.pack?
标签: python attributeerror nonetype