[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: python-shell-send-region uses wrong encoding?
From: |
Stefan Monnier |
Subject: |
Re: python-shell-send-region uses wrong encoding? |
Date: |
Tue, 29 Oct 2013 13:28:38 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> This is the same output that I get when I run the script in a terminal.
> However, if I select the lines after 'from __future__ ...' until the end and
> do python-shell-send-region (C-c C-r) I get this output instead:
> u'W\xf6rterbuch'
> u'W\xc3\xb6rterbuch'
> The second line of output seems to indicate that the text was sent in a
> different encoding compared to python-shell-send-buffer.
No, it indicates that Python interpreted the bytes sent by Emacs in
a different way: the first line (where you explicitly asked for a utf-8
decoding) indicates that the bytes indeed use the right utf-8 encoding,
but the second indicates that Python does not decode the input as utf-8
but as something else (presumably latin-1).
E.g. the patch below (which causes python-shell-send-string to tell
Python that the file sent is using utf-8) should fix your problem (tho
it's not a proper fix, since we shouldn't hardcode utf-8 here, but copy
which ever -*- coding: -*- coding is in the file).
Fabián, could you write a cleaner fix?
Stefan
=== modified file 'lisp/progmodes/python.el'
--- lisp/progmodes/python.el 2013-10-07 18:51:26 +0000
+++ lisp/progmodes/python.el 2013-10-29 17:25:11 +0000
@@ -2047,6 +2047,7 @@
(temp-file-name (make-temp-file "py"))
(file-name (or (buffer-file-name) temp-file-name)))
(with-temp-file temp-file-name
+ (insert "# -*- coding: utf-8 -*-")
(insert string)
(delete-trailing-whitespace))
(python-shell-send-file file-name process temp-file-name))
RE: python-shell-send-region uses wrong encoding?, Drew Adams, 2013/10/29
Re: python-shell-send-region uses wrong encoding?,
Stefan Monnier <=
Re: python-shell-send-region uses wrong encoding?, Ernest Adrogué, 2013/10/31
Re: python-shell-send-region uses wrong encoding?, Ernest Adrogué, 2013/10/31
Re: python-shell-send-region uses wrong encoding?, Stefan Monnier, 2013/10/31