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

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

Lists of animals

Lists of aquarium life

Lists of biologists by author abbreviation

Lists of cultivars

代码

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

运行结果:

最新文章

  1. iOS开发之SQLite-C语言接口规范(一)——Ready And Open Your SQLite
  2. PHP定时器实现每隔几秒运行一次
  3. 【转】Struts1.x系列教程(3):属性(资源)文件乱码问题的解决之道
  4. BWT (Burrows–Wheeler_transform)数据转换算法
  5. Maven学习总结(六)——Maven与Eclipse整合
  6. Windows下msysGit使用及相关配置
  7. 转载:Linux kernel rt_mutex的背景和简介
  8. JS 生成26个大小写字母
  9. Java 字典排序
  10. 树莓派:使用OpenCV调用自带的摄像头.
  11. Excel快捷键
  12. [ES6] for..in && for..of
  13. springmvc国际化 基于浏览器语言的国际化配置
  14. Elasticsearch5中安装Elasticsearch-head插件
  15. mybatis快速入门(八)-spring-mybatis动态代理整合
  16. oracle sql model从句demo
  17. 去除input的自动填充色
  18. [Objective-C语言教程]数组(14)
  19. HttpServletResponse实现文件下载
  20. Scrum Meeting NO.9

热门文章

  1. PHP——仿造微信OpenId
  2. HTML5 自定义属性 data-*属性名一定要小写吗?
  3. freemarker使用shiro标签(spring boot)
  4. LeetCode 1039. Minimum Score Triangulation of Polygon
  5. Linux 重启 PHP-FPM 命令
  6. vscode 添加eslint插件
  7. dropbox icloud and nustore
  8. 区间DP训练
  9. hive 整合ranger
  10. VLAD算法浅析, BOF、FV比较