search

Home  >  Q&A  >  body text

protobuf - grpc python,client怎样给map类型填值?

.proto文件如果这个样子

message HelloRequired {
  
    map<string, string> args = 1;
    
}    
PHPzPHPz2911 days ago726

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-18 10:11:14

      test_dict = {}
      test_dict["key1"] = "value1"
      test_dict["key2"] = "value2"
    

    It seems like just putting one of these in directly?

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:11:14

    Assign values ​​as follows

        import hellorequired_pb2
        test = hellorequired_pb2.HelloRequired()
        test.args["key1"] = "value1"
        test.args["key2"] = "value2"
        print test
        """
        输出如下
        args {
          key: "key1"
          value: "value1"
      }
       args {
         key: "key2"
         value: "value2"
      }
        """

    reply
    0
  • Cancelreply