Print human friendly Protobuf message

后端 未结 3 1003
清歌不尽
清歌不尽 2021-02-18 14:23

I couldn\'t find anywhere a possibility to print a human friendly content of a Google Protobuf message.

Is there an equivalent in Python for Java\'s toString()

3条回答
  •  眼角桃花
    2021-02-18 15:08

    As answered, print and __str__ do work, but I wouldn't use them for anything more than debug strings.

    If you're writing to something that users could see, it's better to use the google.protobuf.text_format module, which has some more controls (e.g. escaping UTF8 strings or not), as well as functions for parsing text-format as protobufs.

提交回复
热议问题