Unicode, command-line and idle

Kent Johnson kent at kentsjohnson.com
Wed Apr 12 06:40:33 EDT 2006


a.serrano at vielca.com wrote:
> Hello again, I've investigated a little bit and this is what I found:
> 
> If I run IDLE and type
> 
>>>> import sys
>>>> sys.stdin.encoding
> 
> I get
> 
> 'cp1252'
> 
> But if I have a whatever.py file (it can even be a blank file), I edit
> it with IDLE, I press F5 (Run Module) and then type:
> 
>>>> import sys
>>>> sys.stdin.encoding
> 
> I get
> 
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in ?
>     sys.stdin.encoding
> AttributeError: PyShell instance has no attribute 'encoding'
> 
> So when I have the following code in a file:
> 
> # -*- coding: cp1252 -*-
> import sys
> text1 = u'españa'
> text2 = unicode(raw_input(), sys.stdin.encoding)
> if text1 == text2:
>     print 'same'
> else:
>     print 'not same'
> 
> and I press F5 (Run Module) I get:
> 
> Traceback (most recent call last):
>   File "C:\test.py", line 4, in ?
>     text2 = unicode(raw_input(), sys.stdin.encoding)
> AttributeError: PyShell instance has no attribute 'encoding'
> 
> This same code works if I just double-click it (run it in the windows
> console) instead of using IDLE.
> 
> I'm using Python 2.4.3 and IDLE 1.1.3.

FWIW all of the above give me 'cp1252', not AttributeError, and the type 
of sys.stdin on my system is idlelib.rpc.RPCProxy, not PyShell.

Python 2.4.3 and IDLE 1.1.3 on Win2k

Kent



More information about the Python-list mailing list