does raw_input() return unicode?

Duncan Booth duncan.booth at invalid.invalid
Tue Oct 10 09:45:01 CEST 2006

"Stuart McGraw" <smcg4191zz at> wrote:

> So, does raw_input() ever return unicode objects and if
> so, under what conditions?
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
>>> sys.stdin = codecs.getreader(sys.stdin.encoding)(sys.stdin)
>>> raw_input()
hello world
still going?
u'hello world'

More information about the Python-list mailing list