Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't input Unicode in Internal Console #1079

Closed
spyder-bot opened this issue Feb 17, 2015 · 3 comments
Closed

Can't input Unicode in Internal Console #1079

spyder-bot opened this issue Feb 17, 2015 · 3 comments

Comments

@spyder-bot
Copy link
Collaborator

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?

  1. Open internal console
    1. 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

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-07-04T08:23:07Z

Thanks for the fix. I'll try to push it soon.

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.

Status: Accepted
Owner: ccordoba12
Labels: Cat-Console MS-v2.2

@spyder-bot
Copy link
Collaborator Author

From ruoyu0...@gmail.com on 2012-07-04T17:36:48Z

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.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-07-06T09:32:15Z

This issue was updated by revision a5232108e9cc .

Thanks to ruoyu0088@gmail.com for the fix

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant