Python + Win32: Cut/Paste w/o GUI

TeaAndBikkie teaandbikkie at
Mon Oct 7 14:08:52 CEST 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
    clip_data = win32clipboard.GetClipboardData(win32con.CF_TEXT)
    clip_text = str(clip_data)
    return clip_text

--regards, Misha

More information about the Python-list mailing list