Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print UTF-8 characters in cmd using python

# -*- 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 "ÆØÅ"?

like image 965
Tyilo Avatar asked Sep 06 '25 03:09

Tyilo


2 Answers

Bit late to the party here, try

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
print "ÆØÅ"
like image 55
danodonovan Avatar answered Sep 07 '25 20:09

danodonovan


You can force unicode when printing:

print u'ÆØÅ'
like image 37
msvalkon Avatar answered Sep 07 '25 19:09

msvalkon