stratis
stratis

Reputation: 8042

Unicode and locale issues

I am struggling to write a Python (version 2.7) script which makes use of some unicode properties. The problem arises when I attempt to use embedded locale package. Here is the code snippet that I am having issues with:

# -*- coding: utf-8 -*-
import datetime
import os
import locale
locale.setlocale(locale.LC_ALL, 'greek')
day = datetime.date.today()
dayFull = day.strftime('%A')
myString = u"ΚΑΛΗΜΕΡΑ"
print myString
print dayFull

While dayFull prints the current day name just fine (in greek letters), myString comes out in console as question mark characters. How can I fix it, can someone please point out my mistake here?

P.S. My system is a Windows 7 machine.

Upvotes: 2

Views: 571

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177516

Use the correct Greek code page in the console, as well as a font that supports Greek characters, such as Consolas. This worked for me in Windows 7 and Python 2.7.3:

C:\>chcp 1253
Active code page: 1253

C:\>python temp.py
ΚΑΛΗΜΕΡΑ
Σάββατο

FYI, Python 3.3 works correctly with the (also Greek) 737 code page, but Python 2.7 prints:

C:\>temp.py
????????
Σάββατο

Upvotes: 3

Related Questions