python实践项目五:操作剪贴板-pyperclip模块

描述:读取剪贴板的内容,修改该内容,再将修改后的内容重新写进剪贴板

注意:执行程序代码前需保证剪贴板有内容,可复制以下内容来测试:

Lists of animals

Lists of aquarium life

Lists of biologists by author abbreviation

Lists of cultivars

代码

 1 #!/usr/bin/python
 2 # -*- coding: UTF-8 -*-
 3 #执行程序之前剪贴板的内容:
 4 '''
 5 Lists of animals
 6 Lists of aquarium life
 7 Lists of biologists by author abbreviation
 8 Lists of cultivars
 9 '''
10 #执行程序之后剪贴板的内容:
11 '''
12 * Lists of animals
13 * Lists of aquarium life
14 * Lists of biologists by author abbreviation
15 * Lists of cultivars
16 '''
17 import pyperclip
18 text = pyperclip.paste()#获得剪贴板的内容,返回一个字符串
19 print '之前的剪贴板内容:\n',text
20 lines = text.split('\n')  #以‘\n’为分隔符分割字符串,并返回一个列表,参考资料:https://www.runoob.com/python/att-string-split.html
21 for i in range(len(lines)):
22     lines[i] = '* ' + lines[i]
23     newtext = '\n'.join(lines) #用‘\n’连接列表的每一个元素,并返回一个字符串,参考链接:https://www.runoob.com/python/att-string-join.html
24 pyperclip.copy(newtext) #将text写入剪贴板
25 print '执行程序后的剪贴板内容:\n',newtext

运行结果:

 

转载于:https://www.cnblogs.com/heyangblog/p/11139753.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值