Python + Win32: Cut/Paste w/o GUI

TeaAndBikkie teaandbikkie at aol.com
Tue Oct 8 09:08:54 EDT 2002


>Subject: Re: Python + Win32: Cut/Paste w/o GUI
Mark Hammond wrote:
>TeaAndBikkie wrote:
>> I use the following variation, in case the clipboard contains other stuff
>than
>> text... does anyone know if this is necessary?
>> 
>> def GetClipboardText():
>>     import win32clipboard, win32con
>>     win32clipboard.OpenClipboard(0)
>>     clip_data = win32clipboard.GetClipboardData(win32con.CF_TEXT)
>>     clip_text = str(clip_data)
>>     win32clipboard.CloseClipboard()
>>     return clip_text
>> 
>> --regards, Misha
>
>The docs for GetClipboardData say:
>
>Parameters
>format=CF_TEXT : int
>
>So the param is not necessary.  As the result is always a string object 
>(except when format is CF_UNICODETEXT), the str() is not necessary 
>either.  If the clipboard contains non text information (such as a 
>bitmap), requesting it as such may will return a string, but requesting 
>it as CF_TEXT is likely to give an exception.

Thanks for pointing this out Mark. I missed this the first time :)

--Misha




More information about the Python-list mailing list