def fl(l):
if len(l) > 2:
return '%s-%s' % (l[0], l[-1])
elif len(l) == 2:
return '%s, %s' % (l[0], l[-1])
else:
return '%s' % l[0]
def cc(l):
r = []
b = []
for i in l:
if len(b) > 0:
if i - b[-1] == 1:
b.append(i)
else:
r.append(fl(b))
b = [i]
else:
b.append(i)
else:
r.append(fl(b))
return ', '.join(r)
from cStringIO import StringIO
import win32clipboard
from PIL import Image
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
image = Image.open('image.jpg')
output = StringIO()
image.convert("RGB").save(output, "BMP")
send_to_clipboard(win32clipboard.CF_DIB, output.getvalue())