2

I guess I need some help regarding encodings in Python (2.6) and Eclipse. I used Google and the so-search and tried a lot of things but as a matter of fact I don't get it.

So, how do I achieve, that the output in the Eclipse console is able to show äöü etc.?

I tried: Declaring the document encoding in the first line with

# -*- coding: utf-8 -*-

I changed the encoding settings in Window/Preferences/General/Workspace and Project/Properties to UTF-8

As nothing changed I tried the following things alone and in combination but nothing seemed to work out:

  • Changing the stdout as mentioned in the Python Cookbook:

    sys.stdout = codecs.lookup("utf-8")-1

  • Adding an unicode u:

print u"äöü".encode('UTF8')

  • reloading sys (I don't know what for but it doesn't work either ;-))

I am trying to do this in order to debug the encoding-problems I have in my programs... (argh)

Any ideas? Thanks in advance!

EDIT: I work on Windows 7 and it is EasyEclipse

8
  • By adding a # -*- coding: utf-8 -*- you will set the encoding information which is then used by the Python parser to interpret the file using the given encoding (See PEP 0263). So only interesting if you are using Umlauts in the source file. What do you see when you start the python interpreter on its own and print 'üöä'? Commented Sep 26, 2013 at 9:07
  • @robert-caspary In the interpreter I get a correct output äöü Commented Sep 26, 2013 at 12:01
  • Which console font are you using in eclipse? (Preferences -> General -> Appearance) At least on my Windows PC I could break my output for umlauts by using e.g. the Terminal font. Commented Sep 26, 2013 at 12:44
  • @robert-caspary Thanks for your help! Unfortunately: I changed the console font to Arial but still 'print "ö"' results in ö Commented Sep 26, 2013 at 13:04
  • @robert-caspary no, print 'ö' gives ö Commented Sep 26, 2013 at 15:34

2 Answers 2

7

Got it! If you have the same problem go to

Run/Run Configurations/Common and select the UTF-8 (e.g.) as console encoding.

So, finally, print "ö" results in "ö"

Sign up to request clarification or add additional context in comments.

Comments

3

Even this is a bit old question, I'm new in StackOverflow and I'd like to contribute a bit. You can change the default encoding in Eclipse (currently Neon) for the all text editors from the menu Window -> Preferences -> General -> Workspace : Text file encoding

Item Path

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.