Stripping characters from windows clipboard with win32clipboard from excel

MRAB python at mrabarnett.plus.com
Wed Sep 18 15:40:53 EDT 2013


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]




More information about the Python-list mailing list