Oh, indeed enum_types_by_name is what you want - my bad!

On Thu, Aug 26, 2010 at 5:51 PM, Mike <mspie...@gmail.com> wrote:

> Got it, Thanks!
>
> In your first statement, I believe the method is actually
> "enum_types_by_name" - at least that's what worked for me.
>
> On Aug 26, 12:29 am, Jason Hsueh <jas...@google.com> wrote:
> > 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 fromhttp://
> code.google.com/apis/protocolbuffers/docs/reference/python/ind...
> > )
> >
> >
> >
> > 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>
> <protobuf%2bunsubscr...@googlegroups.c om>
> > > .
> > > 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<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.

Reply via email to