在python中使用google protobuffers反射 [英] using google protobuffers reflection in python

查看:47
本文介绍了在python中使用google protobuffers反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式通过名称为 python 中的 google protobuffer 对象设置字段值.我检查了文档和 API,但我不清楚,而且我找不到任何示例.

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.

我想做类似的事情:

protoBufObj.set_field('foo', 42)

谢谢.

推荐答案

如果你有任何 x.foo = 42 工作的 Python 对象,setattr(x, 'foo', 42) 应该具有完全相同的效果.这是一个内置的 Python 函数,与 protobuffers 无关.

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.

这篇关于在python中使用google protobuffers反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆