带有test.photo
文件:
syntax = "proto3";
message Phone {
string number = 1;
}
message User {
Phone phone = 1;
}
与之编译:
python -m grpc_tools.protoc -I. --python_out=. test.proto
运行:
import test_pb2
user = test_pb2.User()
phone = test_pb2.Phone(number = '(123) 456 7890')
user.phone = phone
引发AttributeError
异常:
Assignment not allowed to field "phone" in protocol message object.
是否可以将phone
对象分配给user.phone
属性?