python3.5版本
# coding:utf-8
# 将换行输入的数据变成特定格式字符串
import win32clipboard as w
import win32con
# 设置粘贴板内容
def settext(aString):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_UNICODETEXT, aString)
w.CloseClipboard()
# 获取粘贴板内容
def gettext():
w.OpenClipboard()
t = w.GetClipboardData(win32con.CF_UNICODETEXT)
w.CloseClipboard()
return t
# 以此决定字符串粘贴形式
type = input('参数类型是否为数字:')
inputdata, data = '', ''
for line in iter(input, inputdata):
data += line + '\n'
if type == '1':
str = ','.join(data.split())
else:
str = '\',\''.join(data.split())
str = "'" + str + "'"
settext(str)
a = gettext()
print(a)
python2.7 版本
#coding:utf-8
import win32clipboard as w
import win32con
# 设置粘贴板内容
def settext(aString):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_TEXT, aString)
w.CloseClipboard()
# 获取粘贴板内容
def gettext():
w.OpenClipboard()
t = w.GetClipboardData(win32con.CF_TEXT)
w.CloseClipboard()
return t
# 以此决定字符串拼接形式
type = raw_input('参数类型是否为数字:')
inputdata, data = '', ''
for line in iter(raw_input, inputdata):
data += line + '\n'
if type == '1':
str = ','.join(data.split())
else:
str = '\',\''.join(data.split())
str = "'" + str + "'"
settext(str)
a = gettext()
print(a)