code: def _pretty_dump(self, label, data):
          
          # split data string items to a list of hex value
          dump = ['%02X' % c for c in bytearray(data)]
          # format for TCP or RTU
          if self.__mode == const.MODBUS_TCP:
              if len(dump) > 6:
                  # [MBAP] ...
                  dump[0] = '[' + dump[0]
                  dump[6] += ']'
          elif self.__mode == const.MODBUS_RTU:
              if len(dump) > 4:
                  # ... [CRC]
                  dump[-2] = '[' + dump[-2]
                  dump[-1] += ']'
          # print result
          print(label)
          s = ''
          for i in dump:
              s += i + ' '
          print(s)
docs: Print modbus/TCP frame ('[header]body')
          or RTU ('body[CRC]') on stdout
  
          :param label: modbus function code
          :type label: str
          :param data: modbus frame
          :type data: str (Python2) or class bytes (Python3)