raw_input()返回unicode吗? [英] does raw_input() return unicode?

查看:65
本文介绍了raw_input()返回unicode吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python-2.3的公告中
http://groups.google.com/group/comp....fe25388d?hl=en

它说raw_input():现在可以返回Unicode对象"。


但我在Andrew Kuchling的内容中没有看到任何关于此的内容

" 2.3什么是新的" ,当前用于

raw_input()的python文档也没有说明这一点。在具有cp932(日语)默认语言环境的MS系统上进行测试

显示raw_input()返回的对象是str()对象

包含cp932编码的文本。当我将Python的默认编码设置为cp932(

sitecustomize.py)时,这仍然是真实的。


那么,raw_input()是否会返回unicode对象,如果

那么,在什么条件下呢?

In the announcement for Python-2.3
http://groups.google.com/group/comp....fe25388d?hl=en
it says "raw_input(): can now return Unicode objects".

But I didn''t see anything about this in Andrew Kuchling''s
"2.3 What''s New", nor does the current python docs for
raw_input() say anything about this. A test on a MS
Windows system with a cp932 (japanese) default locale
shows the object returned by raw_input() is a str() object
containing cp932 encoded text. This remained true even
when I set Python''s default encoding to cp932 (in
sitecustomize.py).

So, does raw_input() ever return unicode objects and if
so, under what conditions?

推荐答案

Stuart McGraw < sm ******** @ friizz.RimoovAllZZs.comwrote:
"Stuart McGraw" <sm********@friizz.RimoovAllZZs.comwrote:

那么,raw_input()是否会返回unicode对象,如果

所以,在什么条件下?
So, does raw_input() ever return unicode objects and if
so, under what conditions?



如果从sys.stdin读取返回unicode,则返回unicode。


不幸的是,我不能告诉你如何使用raw_input使sys.stdin返回unicode

。我尝试了我认为应该工作的东西,因为你可以看到

它搞砸了stdin上的缓冲。有没有其他人知道怎么包装

sys.stdin所以它返回unicode但仍然没有缓冲?


Python 2.5(r25:51908,2006年9月19日, 09:52:17)[MSC v.1310 32 bit(Intel)]
win32上


输入help,copyright,credit等等。或许可证或欲获得更多信息。

It returns unicode if reading from sys.stdin returns unicode.

Unfortunately, I can''t tell you how to make sys.stdin return unicode for
use with raw_input. I tried what I thought should work and as you can see
it messed up the buffering on stdin. Does anyone else know how to wrap
sys.stdin so it returns unicode but is still unbuffered?

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.


>> import sys,codecs
sys.stdin.encoding
>>import sys, codecs
sys.stdin.encoding



''cp437''

''cp437''


>> sys.stdin = codecs.getreader(sys.stdin.encoding)(sys.stdin)
raw_input()
>>sys.stdin = codecs.getreader(sys.stdin.encoding)(sys.stdin)
raw_input()



hello world

还在吗?

^ Z

^ Z
u''hello world''

hello world
still going?
^Z
^Z
u''hello world''


>>>
>>>


Stuart McGraw schrieb:
Stuart McGraw schrieb:

那么,是吗? raw_input()曾经返回unicode对象,如果

那么,在什么条件下呢?
So, does raw_input() ever return unicode objects and if
so, under what conditions?



目前,它只在IDLE shell中调用

时返回unicode对象,并且只有输入的字符不能

代表当地的charset。


问候,

马丁

At the moment, it only returns unicode objects when invoked
in the IDLE shell, and only if the character entered cannot
be represented in the locale''s charset.

Regards,
Martin


在10/10/06,Martin v.L?wis < ma **** @ v.loewis.dewrote:
On 10/10/06, "Martin v. L?wis" <ma****@v.loewis.dewrote:

Stuart McGraw schrieb:
Stuart McGraw schrieb:

那么,raw_input()是否会返回unicode对象,如果

那么,在什么条件下呢?
So, does raw_input() ever return unicode objects and if
so, under what conditions?



目前,它只在IDLE shell中调用

时返回unicode对象,并且只有输入的字符不能

表示在语言环境的字符集中。


At the moment, it only returns unicode objects when invoked
in the IDLE shell, and only if the character entered cannot
be represented in the locale''s charset.



为什么只有IDLE? urwid或其他控制台UI工具包是否以某种方式避免了这种情况?


- Theerasak

Why only IDLE? Does urwid or another console UI toolkit avoid this somehow?

-- Theerasak


这篇关于raw_input()返回unicode吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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