Re: does raw_input() return unicode?
On 2006-10-11, Leo Kislov <Leo.Kislov@gma il.comwrote:
>
Considering that all consoles are ascii based, the following
should work where python was able to determine terminal
encoding:
>
class ustdio(object):
def __init__(self, stream):
self.stream = stream
self.encoding = stream.encoding
def readline(self):
return self.stream.rea dline().decode( self.encoding)
>
sys.stdin = ustdio(sys.stdi n)
>
answer = raw_input()
print type(answer)
This interesting discussion led me to a weird discovery:
PythonWin 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond (mhammond@skipp inet.com.au) - see 'Help/About PythonWin' for further copyright information.
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
File "C:\edconn32\Py thon24\Lib\site-packages\python win\pywin\mfc\o bject.py", line 18, in __getattr__
return getattr(o, attr)
AttributeError: encoding
I'm all mindboggley. Just when I thought I was starting to
understand how this character encoding stuff works. Are
PythonWin's stdout and stdin implementations is incomplete?
--
Neil Cerutti
A song fest was hell at the Methodist church Wednesday. --Church
Bulletin Blooper
On 2006-10-11, Leo Kislov <Leo.Kislov@gma il.comwrote:
>Unfortunatel y, 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?
>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?
Considering that all consoles are ascii based, the following
should work where python was able to determine terminal
encoding:
>
class ustdio(object):
def __init__(self, stream):
self.stream = stream
self.encoding = stream.encoding
def readline(self):
return self.stream.rea dline().decode( self.encoding)
>
sys.stdin = ustdio(sys.stdi n)
>
answer = raw_input()
print type(answer)
PythonWin 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond (mhammond@skipp inet.com.au) - see 'Help/About PythonWin' for further copyright information.
>>import sys
>>sys.stdout.en coding
>>sys.stdout.en coding
File "<interacti ve input>", line 1, in ?
File "C:\edconn32\Py thon24\Lib\site-packages\python win\pywin\mfc\o bject.py", line 18, in __getattr__
return getattr(o, attr)
AttributeError: encoding
>>sys.stdin.enc oding
>>>
>>>
understand how this character encoding stuff works. Are
PythonWin's stdout and stdin implementations is incomplete?
--
Neil Cerutti
A song fest was hell at the Methodist church Wednesday. --Church
Bulletin Blooper
Comment