python open 编码格式_python 编码方式大全 fr = open(filename_r,encoding='cp852')

7.8.4. Python Specific Encodings

A number of predefined codecs are specific to Python, so their codec names have no meaning outside Python. These are listed in the tables below based on the expected input and output types (note that while text encodings are the most common use case for codecs, the underlying codec infrastructure supports arbitrary data transforms rather than just text encodings). For asymmetric codecs, the stated purpose describes the encoding direction.

The following codecs provide unicode-to-str encoding [1] and str-to-unicode decoding [2], similar to the Unicode text encodings.

CodecAliasesPurpose

idna

mbcs

dbcs

Windows only: Encode operand according to the ANSI codepage (CP_ACP)

palmos

Encoding of PalmOS 3.5

punycode

Implements

raw_unicode_escape

Produce a string that is suitable as raw Unicode literal in Python source code

rot_13

rot13

Returns the Caesar-cypher encryption of the operand

undefined

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

Produce a string that is suitable as Unicode literal in Python source code

unicode_internal

Return the internal representation of the operand

New in version 2.3: The idna and punycode encodings.

The following codecs provide str-to-str encoding and decoding [2].

CodecAliasesPurposeEncoder/decoder

base64_codec

base64, base-64

Convert operand to multiline MIME base64 (the result always includes a trailing '\n')

bz2_codec

bz2

Compress the operand using bz2

hex_codec

hex

Convert operand to hexadecimal representation, with two digits per byte

quopri_codec

quopri, quoted-printable, quotedprintable

Convert operand to MIME quoted printable

string_escape

Produce a string that is suitable as string literal in Python source code

uu_codec

uu

Convert the operand using uuencode

zlib_codec

zip, zlib

Compress the operand using gzip

str objects are also accepted as input in place of unicode objects. They are implicitly converted to unicode by decoding them using the default encoding. If this conversion fails, it may lead to encoding operations raising UnicodeDecodeError.

[2]

(1, 2) unicode objects are also accepted as input in place of str objects. They are implicitly converted to str by encoding them using the default encoding. If this conversion fails, it may lead to decoding operations raising UnicodeEncodeError.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值