Python + Win32: Cut/Paste w/o GUI

TeaAndBikkie teaandbikkie at aol.com
Mon Oct 7 08:08:52 EDT 2002


>Roger Upole wrote:
>> You can grab the clipboard text using the win32clipboard module.
>> 
>> import win32clipboard
>> win32clipboard.OpenClipboard()
>> print win32clipboard.GetClipboardData()
>> win32clipboard.CloseClipboard()
>

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




More information about the Python-list mailing list