Re: Unicode, command-line and idle
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Unicode, command-line and idle

From: <a.serrano@vielca.com>
Date: Tue Apr 11 2006 - 17:19:29 CEST

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.
Received on Sun Apr 30 22:51:23 2006