用python转换文件格式_如何使用Python将文件格式从Unicode转换为ASCII?

我认为这是一个比你意识到的更深层次的问题。简单地将文件从Unicode转换为ASCII是很容易的,但是,将所有Unicode字符转换为合理的ASCII对应字符(许多字母在两种编码中都不可用)是另一种方法。

以下是网站上的有用引述:Python 1.6 also gets a "unicode"

built-in function, to which you can

specify the encoding:> >>> unicode('hello') u'hello'

> >>> unicode('hello', 'ascii') u'hello'

> >>> unicode('hello', 'iso-8859-1') u'hello'

> >>>All three of these return the same

thing, since the characters in 'Hello'

are common to all three encodings.

Now let's encode something with a

European accent, which is outside of

ASCII. What you see at a console may

depend on your operating system

locale; Windows lets me type in

ISO-Latin-1.> >>> a = unicode('André','latin-1')

> >>> a u'Andr\202'If you can't type an acute letter e,

you can enter the string 'Andr\202',

which is unambiguous.

Unicode supports all the common

operations such as iteration and

splitting. We won't run over them

here.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值