Stripping characters from windows clipboard with win32clipboard from excel
random832 at fastmail.us
random832 at fastmail.us
Fri Sep 13 12:09:29 EDT 2013
On Fri, Sep 13, 2013, at 10:38, stephen.boulet at gmail.com wrote:
> > Hm, that gives me a "Type str doesn't support the buffer API" message.
>
> Aha, I need to use str(s, encoding='utf8').rstrip('\0').
It's not a solution to your problem, but why aren't you using
CF_UNICODETEXT, particularly if you're using python 3? And if you're
not, utf8 is the incorrect encoding, you should be using encoding='mbcs'
to interact with the CF_TEXT clipboard.
Anyway, to match behavior found in other applications when pasting from
the clipboard, I would suggest using:
if s.contains('\0'): s = s[:s.index('\0')]
Which will also remove non-null bytes after the first null (but if the
clipboard contains these, it won't be pasted into e.g. notepad).
More information about the Python-list
mailing list