You can pull this from the descriptors: my_enum_descriptor = SomeMessage.DESCRIPTOR.enums_by_name['MyType'] my_enum_descriptor.values_by_number[SomeMessage.FIRST].name
(See the docs on the descriptor module from http://code.google.com/apis/protocolbuffers/docs/reference/python/index.html ) On Wed, Aug 25, 2010 at 11:07 PM, Mike <mspie...@gmail.com> wrote: > I'm pretty sure this is possible, but I can't seem to figure it out. > There was another post about how to do this in C++, but I couldn't > figure out how to make it work in Python. > > My message is similar to: > > message SomeMessage { > enum MyType { > FIRST = 0; > SECOND = 1; > THIRD = 2; > } > > required MyType type = 0; > } > > > How do I programmatically get the string "FIRST" back if someone > passes me this message with the 'type' field set to SomeMessage.FIRST? > > Something along the lines of... > >>> print SomeMessage.EnumName(SomeMessage.FIRST) > FIRST > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to proto...@googlegroups.com. > To unsubscribe from this group, send email to > protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.