Get package name for protobuf instance at runtime in python

时间:2017-06-12 16:57:03

标签: python protocol-buffers

If I have an instance of a protobuf, is there a way to get the package name from that instance? the docs indicate that

The Python code generated by the protocol buffer compiler is completely unaffected by the package name defined in the .proto file.

Does that mean that there isn't a way to get the package name from a python protobuf instance?

1 个答案:

答案 0 :(得分:1)

如果我有一个protobuf对象response

print type(response)

打印

<class 'weather_pb2.WeatherReply'>

print response.DESCRIPTOR.full_name

打印

weather.WeatherReply

weather是指定WeatherReply的包名称。

相关问题