python decode()函数 (使用登记用于编码的编解码器解码字节)
生活随笔
收集整理的這篇文章主要介紹了
python decode()函数 (使用登记用于编码的编解码器解码字节)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
def decode(self, *args, **kwargs): # real signature unknown"""Decode the bytes using the codec registered for encoding.使用注冊(cè)用于編碼的編解碼器解碼字節(jié)。encodingThe encoding with which to decode the bytes.用于解碼字節(jié)的編碼。errorsThe error handling scheme to use for the handling of decoding errors.The default is 'strict' meaning that decoding errors raise aUnicodeDecodeError. Other possible values are 'ignore' and 'replace'as well as any other name registered with codecs.register_error thatcan handle UnicodeDecodeErrors.用于處理解碼錯(cuò)誤的錯(cuò)誤處理方案。默認(rèn)值為“嚴(yán)格”,這意味著解碼錯(cuò)誤會(huì)引起UnicodeDecodeError。 其他可能的值是'ignore'和'replace'以及在codecs.register_error中注冊(cè)的任何其他可處理UnicodeDecodeErrors的名稱。"""pass
示例:
在UDP客戶端上,使用decode()函數(shù)對(duì)服務(wù)端返回的bytes字符進(jìn)行解碼后打印輸出
結(jié)果:
D:\20191031_tensorflow_yolov3\python\python.exe D:/20191221_network_programming/network_programming/基于UDP協(xié)議的socket/191226_基于UDP協(xié)議的socket_client端.py >>: 莫哈皮 B'\XE8\X8E\XAB\XE5\X93\X88\XE7\X9A\XAE' ('192.168.1.49', 9000) >>: 方法 B'\XE6\X96\XB9\XE6\XB3\X95' ('192.168.1.49', 9000) >>: dd B'DD' ('192.168.1.49', 9000) >>: >>: a A ('192.168.1.49', 9000) >>: 你 你 ('192.168.1.49', 9000) >>: 你 你 ('192.168.1.49', 9000) >>: 哈珀 哈珀 ('192.168.1.49', 9000) >>: 莫哈皮 莫哈皮 ('192.168.1.49', 9000) >>:為啥上面一開始打印出來的是字節(jié)碼??
總結(jié)
以上是生活随笔為你收集整理的python decode()函数 (使用登记用于编码的编解码器解码字节)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 网络编程 套接字的初使用
- 下一篇: python3 字符串前字母(无前缀,前