Reputation: 43
I am following this tutorial for using protocol buffers in python
.
Here is my main.proto
file:
syntax = "proto2"
message Foo {
repeated int32 nums = 1;
}
I cannot access foo.nums
.
Here is the python
script which fails:
import main_pb2
foo = main_pb2.Foo
foo.nums.append(1)
This is what I get when I run it:
AttributeError: type object 'Foo' has no attribute 'nums'.
To make it even more confusing, I can see that Foo
has an attribute called foo.NUMS_FIELD_NUMBER
. What is going on?
Upvotes: 0
Views: 346
Reputation: 43
This line:
foo = main_pb2.Foo
should have been:
foo = main_pb2.Foo()
I wasn't calling the constructor. That fixes the error.
Upvotes: 1