Unicode, command-line and idle

a.serrano at vielca.com a.serrano at vielca.com
Tue Apr 11 11:19:29 EDT 2006


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.

Armando.




More information about the Python-list mailing list