[Python-mode] python mode shell and unicode

Andreas Röhler andreas.roehler at easy-emacs.de
Sun Mar 28 16:56:49 CEST 2010

Max Arnold wrote:
> On Sun, Mar 28, 2010 at 09:25:02AM +0200, Andreas Röhler wrote:
>> Hmm, see inside `python-send-region'
>>   ;; Fixme: Write a `coding' header to the temp file if the region is
>>   ;; non-ASCII.
>> Maybe that indicates the cause?
> I think this is unrelated to the issue because my python code contains no
> unicode characters; they are received from parsed web page and then printed
> to stdout. The problem is with python process spawned by Emacs - its stdout
> encoding is not specified (sys.stdout.encoding is None).
> Maybe this is a python feature: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=415968
> But then I do not understand why manually invoked pyton-shell handles unicode
> characters just fine...

Looks like your problem is rather on the python than the emacs side.

If I change the function in the bugreport given above into

def output(s):
    # print s.decode('utf-8')
    print s

redirecting into FILE with > works

>> You could try `py-execute-file' from python-mode.el
> Sorry, didn't mentioned that I use python.el shipped with emacs. How to disable
> built-in one and enable python-mode.el? 

Download it here


and get it loaded

 How to invoke py-execute-file from
> M-x prompt?


M-x py-execute-file

should do it


> BTW, print u'\xA9' is a nice test for this issue.
> Cheers, Max

More information about the Python-mode mailing list