does raw_input() return unicode?

Stuart McGraw smcg4191zz at friizz.RimoovAllZZs.com
Tue Oct 10 19:02:45 EDT 2006


"Martin v. Löwis" <martin at v.loewis.de> wrote in message news:452b5190$0$29833$9b622d9e at news.freenet.de...
> Stuart McGraw schrieb:
> > So, does raw_input() ever return unicode objects and if
> > so, under what conditions?
>
> 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.

Thanks for the answer.

Also, if anyone has a solution for Duncan Booth's attempt
to wrap stdin, I would find it very useful too!

"Duncan Booth" <duncan.booth at invalid.invalid> wrote:
> "Stuart McGraw" <smcg4191zz at friizz.RimoovAllZZs.com> 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
> 'cp437'
> >>> sys.stdin = codecs.getreader(sys.stdin.encoding)(sys.stdin)
> >>> raw_input()
> hello world
> still going?
> ^Z
> ^Z
> u'hello world'
> >>>




More information about the Python-list mailing list