Unicode, command-line and idle

Kent Johnson kent37 at tds.net
Wed Apr 12 08:09:47 EDT 2006


Egon Frerich wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> What do you have in the IDLE options - General - Default source encoding?

UTF-8

> 
> Egon
> 
> Kent Johnson schrieb am 12.04.2006 12:40:
> 
>> 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
> 
> - --
> Egon Frerich, Freudenbergstr. 16, 28213 Bremen
> 
> E-Mail: e.frerich at nord-com.net
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (MingW32)
> Comment: GnuPT 2.7.2
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFEPOpuuTzybIiyjvURAqKTAJ9omGK03L9p5dHpzjqN9Kz1w6cTYACghO6r
> VG30LibkskG9M2boF/lTc0s=
> =Xl96
> -----END PGP SIGNATURE-----
> 
> 
> 





More information about the Python-list mailing list