python实践项目五:操作剪贴板-pyperclip模块
2024-10-13 06:05:35
描述:读取剪贴板的内容,修改该内容,再将修改后的内容重新写进剪贴板
注意:执行程序代码前需保证剪贴板有内容,可复制以下内容来测试:
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
运行结果:
最新文章
- iOS开发之SQLite-C语言接口规范(一)——Ready And Open Your SQLite
- PHP定时器实现每隔几秒运行一次
- 【转】Struts1.x系列教程(3):属性(资源)文件乱码问题的解决之道
- BWT (Burrows–Wheeler_transform)数据转换算法
- Maven学习总结(六)——Maven与Eclipse整合
- Windows下msysGit使用及相关配置
- 转载:Linux kernel rt_mutex的背景和简介
- JS 生成26个大小写字母
- Java 字典排序
- 树莓派:使用OpenCV调用自带的摄像头.
- Excel快捷键
- [ES6] for..in &;&; for..of
- springmvc国际化 基于浏览器语言的国际化配置
- Elasticsearch5中安装Elasticsearch-head插件
- mybatis快速入门(八)-spring-mybatis动态代理整合
- oracle sql model从句demo
- 去除input的自动填充色
- [Objective-C语言教程]数组(14)
- HttpServletResponse实现文件下载
- Scrum Meeting NO.9