Stripping characters from windows clipboard with win32clipboard from excel
Dave Angel
davea at davea.name
Wed Sep 18 16:13:20 EDT 2013
On 18/9/2013 15:40, MRAB wrote:
> On 18/09/2013 20:28, stephen.boulet at gmail.com wrote:
>> Thanks to everyone for their help. Using everyone's suggestions, this seems to work:
>>
>> import win32clipboard, win32con
>>
>> def getclipboard():
>> win32clipboard.OpenClipboard()
>> s = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
>> win32clipboard.CloseClipboard()
>> if '\0' in s:
>> s = s[:s.index('\0')]
>> return s
>>
> That'll look for a null character and, if it finds one, then look for
> it again. Of course, that probably isn't an issue in practice.
>
> However, an alternative way of doing it is to use the .partition method:
>
> return s.partition('\0')[0]
So is the bug in Excel, in Windows, or in the Python library? Somebody
is falling down on the job; if Windows defines the string as ending at
the first null, then the Python interface should use that when defining
the text defined with CF_UNICODETEXT.
Or maybe it's an example of ill-defined Windows specs.
--
DaveA
More information about the Python-list
mailing list