Wenn ich Python von Mac OS‘Terminal.app starten, erkennt Python die Codierung als UTF-8:Machen Sie Emacs verwenden UTF-8 mit Python interaktiven Modus
$ python3.0
Python 3.0.1 (r301:69556, May 18 2009, 16:44:01)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'UTF-8'
Dies funktioniert genauso für python2.5.
Aber in Emacs ist die Codierung US-ASCII.
Python 3.0.1 (r301:69556, May 18 2009, 16:44:01)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'US-ASCII'
Wie mache ich Emacs mit Python kommunizieren, so dass sys.stdout UTF-8 zu verwenden weiß?
Edit: Da ich die akzeptierte Antwort nicht die rep zu bearbeiten, hier ist genau das, was für mich auf Aquaemacs arbeitete 10.5.6 1.6, Mac OS.
Im python-mode-hook, fügte ich die Linie
(setenv "LANG" "en_GB.UTF-8")
Offenbar Mac OS erfordert "UTF8", während DFA sagt, dass Ubuntu "UTF8" erfordert.
Zusätzlich musste ich die Eingabe/Ausgabe-Codierung festlegen, indem Sie C-x RET p und dann zweimal "utf-8" eingeben. Ich sollte wahrscheinlich herausfinden, wie ich das dauerhaft einstellen kann.
Dank dfa und Jouni für kollektiv helfen, die Antwort zu finden.
Hier ist mein letzter python-mode-hook:
(add-hook 'python-mode-hook
(lambda()
(set (make-variable-buffer-local 'beginning-of-defun-function)
'py-beginning-of-def-or-class)
(define-key py-mode-map "\C-c\C-z" 'py-shell)
(setq outline-regexp "def\\|class ")
(setenv "LANG" "en_GB.UTF-8"))) ; <-- *this* line is new
Anmerkung: auf ubuntu LANG muss auf en_GB.UTF8 eingestellt sein, ohne - – dfa
Danke, ich habe meine Zusammenfassung korrigiert. –
ohne Bindestrich auf ubuntu? Ich benutze immer das Formular UTF-8 und es funktioniert. – u0b34a0f6ae