'How to get top-level protobuf enum value name by number in python?

For example, I have proto-file File.proto:

enum Test {
  ONE = 1;
  TWO = 2;
}

I generate file File_pb2.py with protoc from File.proto. I want in a python-code get string "ONE" (that corresponds to the name of File_pb2.ONE) by value 1 (that corresponds to the value of File_pb2.ONE) from generated file File_pb2.py without defining my own dictionaries. How can I do that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source