geeko
geeko

Reputation: 15

python win32clipboard not working for unicode characters

I have python script which send file paths to clipboard which I paste to a windows dialog box using pywinauto. Here is my part of code using win32clipboard:

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(paths,win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()

Script works fine for paths containing ASCII characters but if file names contains a unicode it gives ????? instead of unicode.What changes should I make to make it work.

Upvotes: 0

Views: 1278

Answers (1)

steinar
steinar

Reputation: 9653

The following code sample works for me:

# -*- coding: utf-8 -*-
import win32clipboard

def set_text(txt):
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(txt, win32clipboard.CF_UNICODETEXT)
    win32clipboard.CloseClipboard()

set_text(u"喵萌茶会字幕组][10月新番.exe")

When I paste after this, I get exactly 喵萌茶会字幕组][10月新番.exe

So the problem has probably to do with the contents of your string paths, either that it's not <type 'unicode'> or it wasn't correctly encoded in a previous step.

Upvotes: 1

Related Questions