2016-06-28 70 views

回答

3

快速查看documentation指示您的FieldDescriptor應該具有label屬性,指示它是可選的,必需的還是重複的。

from google.protobuf.descriptor import FieldDescriptor 

if fd.label == FieldDescriptor.LABEL_OPTIONAL: 
    # do thing 
elif fd.label == FieldDescriptor.LABEL_REQUIRED: 
    # do other thing 
else: 
    # do third thing