标准库中的所有内容都会将 Python 3.0 中的字符串视为 unicode 吗?
既然 Python(从 3.0 开始)是基于 unicode 的,我对标准库的行为方式有点困惑。 CGI 和 urllib 等模块会使用 unicode 字符串还是会使用新的“字节”类型并仅提供编码数据?
I'm a little confused about how the standard library will behave now that Python (from 3.0) is unicode-based. Will modules such as CGI and urllib use unicode strings or will they use the new 'bytes' type and just provide encoded data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从逻辑上讲,许多内容(例如 MIME 编码的邮件消息、URL、XML 文档等)应该以字节而不是字符串的形式返回。 这可能会引起一些恐慌,因为库开始针对 Python 3 进行确定,并且人们发现他们必须比以前更加了解
bytes
/string
转换str
/unicode
...Logically a lot of things like MIME-encoded mail messages, URLs, XML documents, and so on should be returned as
bytes
not strings. This could cause some consternation as the libraries start to be nailed down for Python 3 and people discover that they have to be more aware of thebytes
/string
conversions than they were forstr
/unicode
...关于这个问题(以及一般的 Python)的一大好处是,你可以在解释器中乱搞! Python 3.0 rc1 目前可供下载。
One of the great things about this question (and Python in general) is that you can just mess around in the interpreter! Python 3.0 rc1 is currently available for download.
这里将有两步舞。 请参阅Python 3000 和你。
第 1 步是在 3.0 下运行。
第 2 步是重新考虑您的 API,也许可以做一些更明智的事情。
最有可能的情况是,这些库将切换到 unicode 字符串,以尽可能保持与过去的工作方式兼容。
然后,也许有些人会转向字节,以更正确地实现各种协议的 RFC 标准。
There will be a two-step dance here. See Python 3000 and You.
Step 1 is to get running under 3.0.
Step 2 is to rethink your API's to, perhaps, do something more sensible.
The most likely course is that the libraries will switch to unicode strings to remain as compatible as possible with how they used to work.
Then, perhaps, some will switch to bytes to more properly implement the RFC standards for the various protocols.