5

So , I've searching trough internet and it is so frustrating. When I try to search I get explanations on how to unicode decode and encode files. But I'm not interested in that. I know this is possible since I was able to do that. I don't know what happened. Also, I've tried reinstalling python. Changing the options under the configure IDLE etc. On my laptop there are no problems at all. I can do this:

>> a = 'ć'
>>
>> print a
>> ć

And on my PC I get:

 >> a = 'ć'
 >> Unsupported characters in input

I repeat, I'm not talking about encoding in the program. I'm talking about Python console, and it works on my laptop and worked on my previous machines. There's got to be a solution to this issue.

Also, take look at this:

>>> a = u'ç'
>>> a
u'\xe7'
>>> print a
ç
>>> a = u'ć'
Unsupported characters in input

>>> 
H3NDRX
  • 142
  • 3
  • 14
  • 2
    the windows console does not support that ... idle does and most ide's do however have consoles that support that – Joran Beasley Dec 18 '14 at 22:47
  • Sure that's Python 2.7 on your laptop? – Carsten Dec 18 '14 at 22:47
  • 1
    Are you running Python 2 in one and Python 3 in another? What happens when you try `a = u'ç'`? – Ajean Dec 18 '14 at 22:48
  • I am using IDLE console. And yeah, I'm 101% sure there is Python 2.7 on my laptop. – H3NDRX Dec 18 '14 at 22:50
  • @Ajean >>> a = u'ç' >>> a u'\xe7' >>> print a ç >>> a = u'ć' Unsupported characters in input >>> – H3NDRX Dec 18 '14 at 22:59
  • The question marked as duplicate, [Python, Unicode, and the Windows console](http://stackoverflow.com/questions/5419/python-unicode-and-the-windows-console), does **not** address this specific issue. The IDLE window supports full Unicode, unlike the Windows console, but the error is generated by IDLE itself (not Python). I have the same problem and I've tried mightily to solve it, without success. Python 3's IDLE does not have the same issue. – Mark Ransom Dec 18 '14 at 23:29
  • @Mark ah, my mistake indeed. – Martijn Pieters Dec 18 '14 at 23:56
  • 1
    If you are using non-ascii unicode chars, you best upgrade to the most recent 3.x that you can, which have many fixes for working with unicode. – Terry Jan Reedy Dec 19 '14 at 16:26

2 Answers2

1

The Windows console is limited in what it can display. You can change the code page using the old DOS CHCP command.

CHCP 65001

This will change the code page to UTF-8, and make the console more relaxed. You will probably see a square instead of the actual character, but at least you won't see an error.

zmbq
  • 38,013
  • 14
  • 101
  • 171
-3

Try to:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
...
Valeriy Gaydar
  • 500
  • 1
  • 6
  • 26
  • 6
    **Please** don't cargo cult. You should **never** alter the Python default encoding; there is a *very good reason* that the function is removed from `sys`. Altering the default encoding is like ignoring having broken your leg by strapping a stick to it and keeping on walking rather than to go to a doctor to have the bone set properly. – Martijn Pieters Dec 18 '14 at 22:58
  • 1
    This is apart from the fact that doing this *does not solve the issue at hand*. – Martijn Pieters Dec 18 '14 at 23:00