does raw_input() return unicode?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neil Cerutti

    #16
    Re: does raw_input() return unicode?

    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?
    >
    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.
    >>import sys
    >>sys.stdout.en coding
    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
    >>sys.stdin.enc oding
    >>>
    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

    Comment

    • Martin v. Löwis

      #17
      Re: does raw_input() return unicode?

      Neil Cerutti schrieb:
      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?
      Simple and easy: yes, they are.

      Regards,
      Martin

      Comment

      • Neil Cerutti

        #18
        Re: does raw_input() return unicode?

        On 2006-10-11, Martin v. Löwis <martin@v.loewi s.dewrote:
        Neil Cerutti schrieb:
        >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?
        >
        Simple and easy: yes, they are.
        Oh, phew!

        --
        Neil Cerutti
        Any time I've taken the mound, it's always been the old
        Samson-and-Goliath story written about me. --Randy Johnson

        Comment

        Working...