Python3 unexpected visual interaction with input function and CJK

Sorry for my poor English, this is not my first language.

I have a Python3 file whose contents are simply

print(input(">")) 

When I run it on zsh or bash and write a handle and use my backspace key, an unexpected behavior occurs.

If I press ใ„ด three times, go back three times, I will leave this:

 >ใ„ด 

No matter how many times I press backspace, "ใ…" will not be deleted. Similarly, if I initially write "๋™"

 >๋™ 

and then erase it, there are fatal spaces, and any other characters that I print afterwards look like

 > ๊ฐ€๋‚˜๋‹ค 

This seems to be just a visual problem, as if I had to type โ€œใ„ด ใ„ดใ„ดใ„ดใ„ดโ€ and press backspace until no changes are shown, I would stay with

 >ใ„ดใ„ด 

Next I typed "๋™" and hit enter.

 >ใ„ดใ„ด ๋™ 

will result in

 ๋™ 

print only.

The ultimate weirdness in this is that it only occurs when the input () method is run from a python file. If I had done all this through an interactive shell, nothing unusual would have happened.

This happens on my El Capitan-based MBP, and it seems to be a problem with all CJK keyboards, I did a little testing with the Chinese and Japanese keyboards, and it showed a similar behavior.

Can someone tell me why this is happening and how can I prevent it?

+6
source share

All Articles