最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python encode和decode的妙用

 更新時(shí)間:2009年09月02日 01:27:08   作者:  
做網(wǎng)絡(luò)編程的時(shí)候,經(jīng)常需要把接收到的數(shù)據(jù)用16進(jìn)制的方式打印出來(lái),方便查看。今天發(fā)現(xiàn)在Python下有這樣一個(gè)簡(jiǎn)單的方法。

>>> "hello".encode("hex")
'68656c6c6f'

相應(yīng)的還可以

>>> '68656c6c6f'.decode("hex")
'hello'

查了一下手冊(cè),還有這些codec可用

Codec

Aliases

Operand type

Purpose

base64_codec base64, base-64 byte string Convert operand to MIME base64
bz2_codec bz2 byte string Compress the operand using bz2
hex_codec hex byte string Convert operand to hexadecimal representation, with two digits per byte
idna   Unicode string Implements RFC 3490. New in version 2.3. See also encodings.idna
mbcs dbcs Unicode string Windows only: Encode operand according to the ANSI codepage (CP_ACP)
palmos   Unicode string Encoding of PalmOS 3.5
punycode   Unicode string Implements RFC 3492. New in version 2.3.
quopri_codec quopri, quoted-printable, quotedprintable byte string Convert operand to MIME quoted printable
raw_unicode_escape   Unicode string Produce a string that is suitable as raw Unicode literal in python source code
rot_13 rot13 Unicode string Returns the Caesar-cypher encryption of the operand
string_escape   byte string Produce a string that is suitable as string literal in python source code
undefined   any Raise an exception for all conversions. Can be used as the system encoding if no automatic coercion between byte and Unicode strings is desired.
unicode_escape   Unicode string Produce a string that is suitable as Unicode literal in python source code
unicode_internal   Unicode string Return the internal representation of the operand
uu_codec uu byte string Convert the operand using uuencode
zlib_codec zip, zlib byte string Compress the operand using gzip

相關(guān)文章

  • 對(duì)python特殊函數(shù) __call__()的使用詳解

    對(duì)python特殊函數(shù) __call__()的使用詳解

    今天小編就為大家分享一篇對(duì)python特殊函數(shù) __call__()的使用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-07-07
  • Python獲取指定日期是"星期幾"的6種方法

    Python獲取指定日期是"星期幾"的6種方法

    在Python進(jìn)行數(shù)據(jù)分析時(shí),按照日期進(jìn)行分組匯總也是被需要的,比如會(huì)找到銷量的周期性規(guī)律。本文將以2022-02-22為例,演示Python獲取指定日期是“星期幾”的6種方法,需要的可以參考一下
    2022-03-03
  • Jupyter加載文件的實(shí)現(xiàn)方法

    Jupyter加載文件的實(shí)現(xiàn)方法

    這篇文章主要介紹了Jupyter加載文件的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-04-04
  • Python變量及數(shù)據(jù)類型用法原理匯總

    Python變量及數(shù)據(jù)類型用法原理匯總

    這篇文章主要介紹了Python變量及數(shù)據(jù)類型用法原理匯總,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • python pandas.DataFrame選取、修改數(shù)據(jù)最好用.loc,.iloc,.ix實(shí)現(xiàn)

    python pandas.DataFrame選取、修改數(shù)據(jù)最好用.loc,.iloc,.ix實(shí)現(xiàn)

    今天小編就為大家分享一篇python pandas.DataFrame選取、修改數(shù)據(jù)最好用.loc,.iloc,.ix實(shí)現(xiàn)。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • 使用 Python 處理 JSON 格式的數(shù)據(jù)

    使用 Python 處理 JSON 格式的數(shù)據(jù)

    JSON 是一個(gè)很好的選擇。如果你對(duì) Python 有所了解,就更加事半功倍了。下面就來(lái)介紹一下如何使用 Python 處理 JSON 數(shù)據(jù)。感興趣的朋友跟隨小編一起看看吧
    2019-07-07
  • 基于python log取對(duì)數(shù)詳解

    基于python log取對(duì)數(shù)詳解

    今天小編就為大家分享一篇基于python log取對(duì)數(shù)詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • 思考分析Python運(yùn)算中?a+=b?和?a=a+b是否相等

    思考分析Python運(yùn)算中?a+=b?和?a=a+b是否相等

    這篇文章主要為大家介紹了Python運(yùn)算中a+=b和a=a+b是否相等及原理思考分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • 詳細(xì)聊聊為什么Python中0.2+0.1不等于0.3

    詳細(xì)聊聊為什么Python中0.2+0.1不等于0.3

    最近在學(xué)習(xí)過(guò)程中發(fā)現(xiàn)在計(jì)算機(jī)JS時(shí)發(fā)現(xiàn)了一個(gè)非常有意思事,0.1+0.2的結(jié)果不是0.3,而是0.30000000000000004,下面這篇文章主要給大家介紹了關(guān)于為什么Python中0.2+0.1不等于0.3的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • Python中SQLAlchemy庫(kù)的使用方法分析

    Python中SQLAlchemy庫(kù)的使用方法分析

    SQLAlchemy 是Python SQL工具包和對(duì)象關(guān)系映射器(ORM),允許Python開(kāi)發(fā)者在應(yīng)用程序中使用SQL來(lái)交互,而無(wú)需處理數(shù)據(jù)庫(kù)的具體細(xì)節(jié),本文給大家詳細(xì)分析了Python中SQLAlchemy庫(kù)的使用方法,需要的朋友可以參考下
    2024-08-08

最新評(píng)論

松原市| 古田县| 农安县| 新津县| 新昌县| 海城市| 宁远县| 临城县| 南宁市| 通道| 锡林郭勒盟| 靖远县| 志丹县| 扎赉特旗| 西充县| 资中县| 剑阁县| 克拉玛依市| 浦城县| 盘锦市| 黎城县| 大洼县| 紫云| 文水县| 宁夏| 永新县| 奉贤区| 镶黄旗| 尖扎县| 皮山县| 梓潼县| 叙永县| 淮安市| 甘德县| 湘乡市| 巴彦淖尔市| 宝山区| 万山特区| 湾仔区| 马鞍山市| 顺昌县|