python';非类型';对象没有属性';从"u字节';
请帮帮我,这让我快发疯了python';非类型';对象没有属性';从"u字节';,python,attributeerror,nonetype,Python,Attributeerror,Nonetype,请帮帮我,这让我快发疯了 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个独立的字节,我需要
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位整数。如果我在python命令行中键入最后4条语句,它将非常有效,只是在函数中没有。
无论我如何格式化代码,我总是收到以下错误:
new_value = int.from_bytes(value, byteorder='big')
AtrributeError: 'NoneType' object has no attribute 'from_bytes'
在某些地方,您已将
int
重新定义为无。以及Daniel提到的内容-这是导致错误的原因,您最好使用struct
模块,而不是:
value= ser.read(1)
new_value = int.from_bytes(value, byteorder='big')
您可以使用:
import struct
int_values = struct.unpack('>16B', ser.read(16))
也许可以考虑<代码> Stutt.Pox<代码>。