Python AttributeError:不允许分配到复合字段“;id”;协议内消息对象
我正在使用python协议缓冲区来分配值。但产生的错误如前所述 原始文件:Python AttributeError:不允许分配到复合字段“;id”;协议内消息对象,python,protocol-buffers,Python,Protocol Buffers,我正在使用python协议缓冲区来分配值。但产生的错误如前所述 原始文件: message MovingObject{ // The ID of the object. // optional Identifier id = 1; // The base parameters of the vehicle. // // \note The bounding box does NOT includes mirrors for vehicles. // optional BaseMoving ba
message MovingObject{
// The ID of the object.
//
optional Identifier id = 1;
// The base parameters of the vehicle.
//
// \note The bounding box does NOT includes mirrors for vehicles.
//
optional BaseMoving base = 2;
// The type of the object.
//
optional Type type = 3;}
python文件:
mo = osi_object_pb2.MovingObject()
mo.id = 12
print(mo.id)
您正试图将
int
分配给标识符
。您必须将字段类型更改为映射到Python int的,例如,int32
,或者分配标识符的实例。Hello。很抱歉,我不明白分配标识符消息的实例是什么意思。你能解释一下吗?很抱歉我说的很蹩脚,但我对这一点完全陌生。Protobuf消息中的字段有类型,就像C或Java等编程语言中的变量一样。由于您的id
字段具有类型Identifier
,因此您只能将Identifier
消息分配给它,而不是像12
这样的简单int
。有关详细信息,请参见。@MuhammadShaheerMunir请投票选出有用的答案,并将(最佳)正确答案标记为解决方案