如何分配给重复字段? [英] How to assign to repeated field?
本文介绍了如何分配给重复字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 python 中使用协议缓冲区,我有一个 Person
消息
I am using protocol buffers in python and I have a Person
message
repeated uint64 id
但是当我尝试为它分配一个值时:
but when I try to assign a value to it like:
person.id = [1, 32, 43432]
我收到一个错误:不允许为协议消息对象中的重复字段id"赋值
如何为重复字段赋值?
I get an error: Assigment not allowed for repeated field "id" in protocol message object
How to assign a value to a repeated field ?
推荐答案
根据 文档,您不能直接分配给重复的字段.在这种情况下,您可以调用 extend
将列表中的所有元素添加到字段中.
As per the documentation, you aren't able to directly assign to a repeated field. In this case, you can call extend
to add all of the elements in the list to the field.
person.id.extend([1, 32, 43432])
这篇关于如何分配给重复字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文