4
# -*- coding: utf-8 -*-
print "ÆØÅ"

When running the above script in Windows 7 with python 2.7.3 using cmd, powershell or cygwin, I get this output:

ÆØÅ

The file is a UTF-8 file and works fine in my text editor. How can I make it print "ÆØÅ"?

6
  • 1
    Does print u'ÆØÅ' work? Commented Mar 4, 2013 at 11:57
  • Did you try LANG=en_US.UTF-8 python yourscript.py? Commented Mar 4, 2013 at 11:57
  • @msvalkon That worked perfectly and from __future__ import unicode_literals works too. @ThomasOrozco I have no idea how to do that in cmd. Commented Mar 4, 2013 at 12:02
  • Well then there you go :) Commented Mar 4, 2013 at 12:05
  • 2
    Windows UTF8 printing in the console is notoriously troublesome. You need to use the correct codepage (65001), for Python versions before 3.2, add support for that codepage to Python, and use the correct font to display unicode glyphs. Commented Mar 4, 2013 at 12:12

2 Answers 2

5

Bit late to the party here, try

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
print "ÆØÅ"
Sign up to request clarification or add additional context in comments.

1 Comment

Using the from __future__ import unicode_literals is useful in an interactive python session. Thank you for it.
3

You can force unicode when printing:

print u'ÆØÅ'

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.