第一步:
pip install pywin32
第二布:
import win32clipboard as w
import win32con
import os
def get_text():
w.OpenClipboard()
d = w.GetClipboardData(win32con.CF_TEXT)
w.CloseClipboard()
return d.decode('GBK')
def set_text(aString):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_TEXT, aString)
w.CloseClipboard()
# 读取剪切板内容
ss = get_text()
with open('D:\\'+'临时文件.txt','w')as f:
f.write(ss)
with open('D:\\'+'临时文件.txt','r')as f:
ss=f.readlines()
os.remove('D:\\临时文件.txt')
for i in range(len(ss)):
if i%2==0:
ss[i]=ss[i].replace('\n','').replace('\t','')
ss[i]='\''+ss[i]+'\''
with open('D:\\' + '临时文件.txt', 'a')as f:
f.write(ss[i]+'\n')
with open('D:\\'+'临时文件.txt','r')as f:
ss=f.readlines()
os.remove('D:\\临时文件.txt')
for i in range(len(ss)):
if i%2==0:
ss[i]=ss[i]+':'
else:
ss[i]=ss[i]+','
print(ss[i].replace('\n',''))
效果展示(直接复制就可以用了):
|