Reputation: 185
I have below proto file
syntax = "proto3";
package my_proto;
message ID
{
optional uint64 id_upper = 1;
optional uint64 id_lower = 2;
}
message mymessage
{
optional ID id = 1;
}
And I tried assigning value to ID field using below python script
import my_proto_pb2
message = my_proto_pb2.mymessage()
id = message.id()
id.id_upper = 10
id.id_lower = 20
But I got below error:
Traceback (most recent call last):
File "create_message.py", line 4, in <module>
id = message.id()
TypeError: 'ID' object is not callable
May I know why it is throwing this error? Also, how can I assign value to an 'optional' message field?
Upvotes: 1
Views: 1855
Reputation: 556
Try removing parenthesis here:
id = message.id()
to id = message.id
another way to do this:
thisid = ID()
thisid.id_upper = 10
thisid.id_lower = 20
message = mymessage()
message.id = thisid
Upvotes: 1