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

python encode和decode的妙用

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

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

相應(yīng)的還可以

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

查了一下手冊,還有這些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)文章

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

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

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

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

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

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

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

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

    這篇文章主要介紹了Python變量及數(shù)據(jù)類型用法原理匯總,文中通過示例代碼介紹的非常詳細(xì),對大家的學(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à)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • 使用 Python 處理 JSON 格式的數(shù)據(jù)

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

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

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

    今天小編就為大家分享一篇基于python log取對數(shù)詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    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í)過程中發(fā)現(xiàn)在計(jì)算機(jī)JS時發(fā)現(xiàn)了一個非常有意思事,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庫的使用方法分析

    Python中SQLAlchemy庫的使用方法分析

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

最新評論

雷州市| 延吉市| 深水埗区| 扎囊县| 镇原县| 汾西县| 凭祥市| 林州市| 阆中市| 广德县| 太仓市| 泸定县| 东城区| 左贡县| 乐都县| 长治市| 房山区| 沙田区| 宁明县| 资阳市| 徐闻县| 长葛市| 邢台县| 玉树县| 阿拉尔市| 元江| 峨边| 威海市| 张家川| 高要市| 九江市| 县级市| 信丰县| 农安县| 大邑县| 安仁县| 保德县| 兰考县| 永善县| 郎溪县| 肥西县|