Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using google protobuffers reflection in python

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.

like image 674
anio Avatar asked Oct 07 '22 22:10

anio


1 Answers

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.

like image 188
Thomas K Avatar answered Oct 10 '22 10:10

Thomas K