You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spyder Version: 2.1.10
Python Version: 2.6.5
Qt Version: 4.7.2, PyQt4 (API v2) 4.8.4 on Windows
What steps will reproduce the problem?
Open internal console
input following code into internal console:
a=u"あ" What is the expected output? What do you see instead? exception raised:
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 336, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Python26\lib\site-packages\spyderlib\widgets\shell.py", line 791, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Python26\lib\site-packages\spyderlib\widgets\shell.py", line 336, in postprocess_keyevent
self._key_enter()
File "C:\Python26\lib\site-packages\spyderlib\widgets\shell.py", line 454, in _key_enter
self.on_enter(command)
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 325, in on_enter
self.execute_command(command)
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 385, in execute_command
self.run_command(cmd)
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 394, in run_command
self.interpreter.stdin_write.write(cmd + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u3042' in position 6: ordinal not in range(128)
Please provide any additional information below
. I debuged this for a while, and here is the result:
def run_command(self, cmd, history=True, new_prompt=True):
print repr(cmd) # << add this line
when I input a="あ", the output is: u'a = "\u3042"'
when I input b=u"あ", the output is: u'b = u"\u3042"'
to get a="あ" works, I need to change the following code in run_command:
But may I ask: why do you want to have unicode on the internal console? I say it because it's a very simple console that show internal messages and lets us explore the Spyder namespace, so I don't clearly see the importance of adding unicode to it.
The internal console widget is very helpful for debugging pyqt applications. I found this unicode issue when I embed it into my developing application which use Japanese.
From ruoyu0...@gmail.com on 2012-06-04T21:14:33Z
Spyder Version: 2.1.10
Python Version: 2.6.5
Qt Version: 4.7.2, PyQt4 (API v2) 4.8.4 on Windows
What steps will reproduce the problem?
input following code into internal console:
a=u"あ" What is the expected output? What do you see instead? exception raised:
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 336, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Python26\lib\site-packages\spyderlib\widgets\shell.py", line 791, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Python26\lib\site-packages\spyderlib\widgets\shell.py", line 336, in postprocess_keyevent
self._key_enter()
File "C:\Python26\lib\site-packages\spyderlib\widgets\shell.py", line 454, in _key_enter
self.on_enter(command)
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 325, in on_enter
self.execute_command(command)
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 385, in execute_command
self.run_command(cmd)
File "C:\Python26\lib\site-packages\spyderlib\widgets\internalshell.py", line 394, in run_command
self.interpreter.stdin_write.write(cmd + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u3042' in position 6: ordinal not in range(128)
Please provide any additional information below
. I debuged this for a while, and here is the result:
def run_command(self, cmd, history=True, new_prompt=True):
print repr(cmd) # << add this line
when I input a="あ", the output is: u'a = "\u3042"'
when I input b=u"あ", the output is: u'b = u"\u3042"'
to get a="あ" works, I need to change the following code in run_command:
self.interpreter.stdin_write.write(cmd.encode("utf-8") + '\n')
to get b=u"あ" works, I need to change the code to:
self.interpreter.stdin_write.write(cmd.encode("unicode_escape") + '\n')
to get both works I change the code in run_command() to:
self.interpreter.stdin_write.write(cmd.encode("utf-8") + '\n')
and then change Interpreter.push() to:
return InteractiveConsole.push(self, "#coding=utf-8\n" + line)
I don't know better method to solve this problem.
Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1079
The text was updated successfully, but these errors were encountered: