Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60738 > unrolled thread
| Started by | mefistofelis@gmail.com |
|---|---|
| First post | 2013-11-28 14:22 -0800 |
| Last post | 2013-11-29 03:48 +0000 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
Cannot print greek letters in Python 2.6 mefistofelis@gmail.com - 2013-11-28 14:22 -0800
Re: Cannot print greek letters in Python 2.6 Chris Angelico <rosuav@gmail.com> - 2013-11-29 09:48 +1100
Re: Cannot print greek letters in Python 2.6 Terry Reedy <tjreedy@udel.edu> - 2013-11-28 20:46 -0500
Re: Cannot print greek letters in Python 2.6 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-29 03:48 +0000
| From | mefistofelis@gmail.com |
|---|---|
| Date | 2013-11-28 14:22 -0800 |
| Subject | Cannot print greek letters in Python 2.6 |
| Message-ID | <ac623a00-9622-42cb-a5a0-6142417e673a@googlegroups.com> |
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
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
data = data.decode('latin1')
send = 'ccc|=:='+data
print data
print send
The following script is running from eventghost programm.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-11-29 09:48 +1100 |
| Message-ID | <mailman.3385.1385678919.18130.python-list@python.org> |
| In reply to | #60738 |
On Fri, Nov 29, 2013 at 9:22 AM, <mefistofelis@gmail.com> wrote: > 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. 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. As a separate point, can you please use something better than Google Groups for posting? There are many far better clients than GG, or you can use the mailing list instead: https://mail.python.org/mailman/listinfo/python-list Google Groups is buggy and should not be used. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-11-28 20:46 -0500 |
| Message-ID | <mailman.3388.1385689587.18130.python-list@python.org> |
| In reply to | #60738 |
On 11/28/2013 5:48 PM, Chris Angelico wrote: > On Fri, Nov 29, 2013 at 9:22 AM, <mefistofelis@gmail.com> wrote: >> 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. When you use a 3rd patch module like 'win32clipboard', you should give a url for the source or doc. Were you using http://docs.activestate.com/activepython/2.4/pywin32/win32clipboard.html There are other programs on Pypi, such as pyclip. > 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. Searching "windows clipboard encoding" return pages such as http://stackoverflow.com/questions/1929812/how-does-cut-and-paste-affect-character-encoding-and-what-can-go-wrong http://msdn.microsoft.com/en-us/library/windows/desktop/ms649015%28v=vs.85%29.aspx http://www.dmst.aueb.gr/dds/sw/outwit/winclip.html These suggest that there should be utf-8 and/or utf-16le versions of any text pasted. http://docs.activestate.com/activepython/2.4/pywin32/win32clipboard__GetClipboardData_meth.html say you could use GetClipboardData(CF_UNICODETEXT) which should reliably give you utf-16le. I get the impression that CF_TEXT should be utf-8 but might not be. EnumClipboardFormats will let you see what is available. > Incidentally, you may find things easier if you switch to Python 3.3 > - quite a bit of Unicode handling is improved in Py3. At least use the *latest* version of 2.7 to get whatever unicode fixes that have been made to 2.x. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-11-29 03:48 +0000 |
| Message-ID | <52980e87$0$29993$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #60738 |
On Thu, 28 Nov 2013 14:22:01 -0800, mefistofelis wrote:
> 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
> win32clipboard.OpenClipboard()
> data = win32clipboard.GetClipboardData()
> win32clipboard.CloseClipboard()
> data = data.decode('latin1')
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, unicodedata.name(c, "<no name>")
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.
UTF-16be
UTF-16
UTF-8
I'd try ISO-8859-7 and UTF-16be first, like this:
import win32clipboard
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
data = data.decode('UTF-16BE')
--
Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web