• 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 '之前的剪贴板内容:
    ',text
    20 lines = text.split('
    ')  #以‘
    ’为分隔符分割字符串,并返回一个列表,参考资料:https://www.runoob.com/python/att-string-split.html
    21 for i in range(len(lines)):
    22     lines[i] = '* ' + lines[i]
    23     newtext = '
    '.join(lines) #用‘
    ’连接列表的每一个元素,并返回一个字符串,参考链接:https://www.runoob.com/python/att-string-join.html
    24 pyperclip.copy(newtext) #将text写入剪贴板
    25 print '执行程序后的剪贴板内容:
    ',newtext

    运行结果:

  • 相关阅读:
    ARCDesktop 学习笔记(一) 添加地图图层
    ARCGIS 开发常用技巧参考
    关于引用动软代码 找不到dll命名空间问题
    银行转账手续费
    Silverlight 笔记
    地图API
    (转)使用ImageBrush替换PictureMarkerSymbol以加强graphic显示性能
    WPF 网摘
    ArcCatalog添加GISserverIP问题
    ARCGIS 10 中文版 3D Analyst Tools等未授权问题
  • 原文地址:https://www.cnblogs.com/heyangblog/p/11139753.html
Copyright © 2020-2023  润新知