using google protobuffers reflection in python

狂风中的少年 提交于 2021-02-07 18:12:50

问题


How can I programatically set a field value by its name for a google protobuffer object in python. I've checked the documentation and API, but its just not clear to me, and I haven't been able to find any examples.

I'd like to do do something like:

protoBufObj.set_field('foo', 42)

Thanks.


回答1:


If you've got any Python object where x.foo = 42 works, setattr(x, 'foo', 42) should have precisely the same effect. This is a built-in Python function, nothing to do with protobuffers.



来源:https://stackoverflow.com/questions/10456399/using-google-protobuffers-reflection-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!