为什么Unicode不是默认编码? [英] why isn't Unicode the default encoding?

查看:121
本文介绍了为什么Unicode不是默认编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我的新手,但我不太明白为什么Unicode仍然需要在Python中进行特殊处理(或许在其他地方使用
)。我现在正在阅读Dive Into Python,并且它一直是

指的是''常规字符串''与''Unicode字符串''以及你如何需要

来回转换。但是为什么现在不认为Unicode是常规的

字符串?出于历史原因,我们仍然使用ASCII和

Latin-1?为什么Unicode不能替换它们所以我们不再需要''u'

前缀或编码技巧?

解决方案

John Salerno写道:

原谅我的新手,但我不太明白为什么Unicode仍然需要在Python中进行特殊处理(也许是
别处)。我现在正在阅读Dive Into Python,它经常指的是''常规字符串''与''Unicode字符串''以及你需要来回转换的方式。但是为什么现在不认为Unicode是常规的字符串呢?出于历史原因,我们仍然使用ASCII和
Latin-1吗?


好​​吧,*我*使用UTF-8,但那里既不是在这里也不是在那里。

为什么Unicode不能取代它们所以我们不再需要''''
前缀或编码技巧?




它会打破很多代码的地狱。尝试使用-U命令行参数

到Python解释器。这使得unicode字符串默认。


[〜]


python -U

Python 2.4.1(#2 ,2005年3月31日,00:05:10)

[GCC 3.3 20030304(Apple Computer,Inc。build 1666)]在darwin上

输入help, ;版权"," credit"或许可证或更多信息。

''foo''
u''foo''




Python非常努力地保持向后兼容。 Python 3.0是

指定的破坏兼容性,所以我们可以删除所有内置的'b
up'发布。现在还有几年的时间,虽然Guido现在已经开始上班了。


-

Robert Kern
ro*********@gmail.com

我已经开始相信整个世界都是一个谜,一个无害的谜团

由于我们疯狂地试图解释它而使它变得可怕,好像它已经
一个潜在的事实。

- Umberto Eco


Robert Kern写道:

好吧,*我*使用UTF-8,但那里既不在这里也不在那里。




我看到UTF-8了很多,但这本特别的书还提到UTF-16最常见的是
。这是真的吗?

为什么Unicode不能取代它们所以我们不再需要''u'
前缀或者编码技巧?



它会打破很多代码的地狱。尝试使用-U命令行参数
到Python解释器。这使得unicode字符串成为默认值。




我认为这可能与它有关,但是我再次认为
认为创建了Unicode作为ASCII和Latin-1的一个子集,所以它们将是兼容的......但是我想这并不容易。 :)


Forgive my newbieness, but I don''t quite understand why Unicode is still
something that needs special treatment in Python (and perhaps
elsewhere). I''m reading Dive Into Python right now, and it constantly
refers to a ''regular string'' versus a ''Unicode string'' and how you need
to convert back and forth. But why isn''t Unicode considered a regular
string by now? Is it for historical reasons that we still use ASCII and
Latin-1? Why can''t Unicode replace them so we no longer need the ''u''
prefix or the encoding tricks?

解决方案

John Salerno wrote:

Forgive my newbieness, but I don''t quite understand why Unicode is still
something that needs special treatment in Python (and perhaps
elsewhere). I''m reading Dive Into Python right now, and it constantly
refers to a ''regular string'' versus a ''Unicode string'' and how you need
to convert back and forth. But why isn''t Unicode considered a regular
string by now? Is it for historical reasons that we still use ASCII and
Latin-1?
Well, *I* use UTF-8, but that''s neither here nor there.
Why can''t Unicode replace them so we no longer need the ''u''
prefix or the encoding tricks?



It would break a hell of a lot of code. Try using the -U command line argument
to the Python interpreter. That makes unicode strings default.

[~]


python -U
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

''foo'' u''foo''



Python tries very hard to remain backwards compatible. Python 3.0 is the
designated "break compatibility so we can remove all of the cruft that''s built
up" release. It is still several years away although Guido is starting to work
on it now.

--
Robert Kern
ro*********@gmail.com

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco


Robert Kern wrote:

Well, *I* use UTF-8, but that''s neither here nor there.



I see UTF-8 a lot, but this particular book also mentions that UTF-16 is
the most common. Is that true?

Why can''t Unicode replace them so we no longer need the ''u''
prefix or the encoding tricks?



It would break a hell of a lot of code. Try using the -U command line argument
to the Python interpreter. That makes unicode strings default.



I figured this might have something to do with it, but then again I
thought that Unicode was created as a subset of ASCII and Latin-1 so
that they would be compatible...but I guess it''s never that easy. :)


这篇关于为什么Unicode不是默认编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆