top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to print greek letters in Python (version 2.6)

+3 votes

I have the following script however when the clipboard contents are greek letters it fails to print them right.
I have used all posible encoding for greek letters including utf8 but to no avail so i just stay with latin1.

Can you suggest a solution?

Here is the script:

import win32clipboard
data = win32clipboard.GetClipboardData()
data = data.decode('latin1')
send = 'ccc|=:='+data
print data
print send 
posted Nov 28, 2013 by Luv Kumar

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+2 votes

That cannot possibly work, since there are no Greek letters in Latin1. If you run this piece of code, you will see no Greek letters except for µ MICRO SIGN.

import unicodedata
for i in range(256):
 c = chr(i).decode('latin-1')
 print c,, "")

I'm not an expert on Windows, but my guess is that the data coming out of the clipboard could be using one of these encodings:

ISO-8859-7 # The code page used by some Greek versions of Windows.

I'd try ISO-8859-7 and UTF-16be first, like this:

import win32clipboard
data = win32clipboard.GetClipboardData()
data = data.decode('UTF-16BE')
answer Nov 29, 2013 by Bob Wise
+1 vote

You need to know what encoding is actually being used. Attempting to decode using arbitrary encodings is doomed to failure. Possibly Windows is using some kind of global default encoding, or possibly you
can query the other program for its encoding, but you're unlikely to succeed by pointing the decode gun in random directions and firing.

Incidentally, you may find things easier if you switch to Python 3.3 - quite a bit of Unicode handling is improved in Py3.

answer Nov 28, 2013 by Meenal Mishra
Similar Questions
0 votes

Is print thread safe? That is, if I have two threads that each call print, say:

print "spam spam spam" # thread 1
print "eggs eggs eggs" # thread 2

I don't care which line prints first, but I do care if the two lines are mixed in together, something like this:

spam spaeggs eggs m seggspams

Does print perform its own locking to prevent this?

0 votes

I need to print the Dictionary in a detailed way.

Current When am print the dictionary am getting like below.

<Details.Value: object at 0x0000027062245160>
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.