I can't figure it out (I missed it in Google's test suite...)
http://code.google.com/p/protobuf/source/browse/trunk/python/google/protobuf/internal/reflection_test.py?r=90
#!/usr/bin/env python
import foobar_pb2
# protoc -I=. --python_out=. foobar.proto
# message Bar {
# optional int32 i = 1 [default = 0];
# optional int32 j = 2 [default = 0];
# }
# message Foo {
# repeated Bar bars = 1;
# }
foo = foobar_pb2.Foo()
# ok, but not reflection
#foo.bars.add()
# AttributeError: Assignment not allowed to repeated field "bars" in
protocol message object.
#setattr(foo, 'bars', foobar_pb2.Bar())
# a stretch; same error
# AttributeError: Assignment not allowed to repeated field "bars" in
protocol message object.
#setattr(foo, 'bars', [foobar_pb2.Bar()])
# cool, something's there:
# {'bars': <google.protobuf.descriptor.FieldDescriptor object at
0x7fbb463bdfd0>}
#print foo.DESCRIPTOR.fields_by_name
# but:
# AttributeError: 'FieldDescriptor' object has no attribute 'append'
#print foo.DESCRIPTOR.fields_by_name['bars'].append(foobar_pb2.Bar())
Thanks for any help;
Jeff
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/protobuf/-/rz_B9UdyhSIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.