Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python';非类型';对象没有属性';从"u字节';_Python_Attributeerror_Nonetype - Fatal编程技术网

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<代码>。