Typing utf-8 characters in python interactively on OS-X

I am trying to enter some spanish character in strings interactively. For example, option+e eto create 'é' so that I make an expression like string="él". This works in the terminal, but in python (any version I have installed, from which I have several), it is not. He does not produce anything. This includes trying to insert characters. This is exactly the problem described in this question , in particular the insertion part and in his commentary on Alex, where he indicates that Alex’s answer does not address the question of copy / paste error regarding utf-8 characters. How can i do this?

+5
source share
2 answers

The library readlinethat Python uses to read interactive input does not accept non-ASCII characters sent by the terminal. This means that either your terminal emulator does not provide UTF-8 encoded characters, or readline is not configured to accept UTF-8 input.

Fortunately, readline is used by many popular programs, including the shell bash, so there is a lot of information on how to make it work. For example, from this article :

How can I enter the input of UTF-8 correctly?

  • In the terminal Inspector:
    • In the "Emulation" section, disable the "Escape non-ASCII" characters.
    • Under Screen, select Unicode (UTF-8) as the character set encoding.
  • Add the following line to .profile:

    export LC_CTYPE=en_US.UTF-8
    
  • Add the following lines to .inputrc:

    set meta-flag on
    set input-meta on
    set output-meta on
    set convert-meta off 
    
  • , source ~/.profile source ~/.inputrc.

+3

u , unicode.

string = u"El avión cayó del cielo"

, ,

#coding: utf8

python Unicode.

0

All Articles