• 在 Wiki 标记中添加无序列表


    项目:在 Wiki 标记中添加无序列表
    在编辑一篇维基百科的文章时,你可以创建一个无序列表,即让每个列表项占
    据一行,并在前面放置一个星号。但是假设你有一个非常大的列表,希望添加前面
    的星号。你可以在每一行开始处输入这些星号,一行接一行。或者也可以用一小段
    Python 脚本,将这个任务自动化。
    bulletPointAdder.py 脚本将从剪贴板中取得文本,在每一行开始处加上星号和空
    格,然后将这段新的文本贴回到剪贴板。例如,如果我将下面的文本复制到剪贴板
    (取自于维基百科的文章“List of Lists of Lists”):
    Lists of animals
    Lists of aquarium life
    Lists of biologists by author abbreviation
    Lists of cultivars
    然后运行 bulletPointAdder.py 程序,剪贴板中就会包含下面的内容:
    * Lists of animals
    * Lists of aquarium life
    * Lists of biologists by author abbreviation
    * Lists of cultivars
    这段前面加了星号的文本,就可以粘贴回维基百科的文章中,成为一个无序列表。


    从剪贴板中复制和粘贴
    你希望 bulletPointAdder.py 程序完成下列事情:
    1.从剪贴板粘贴文本;
    2.对它做一些处理;
    3.将新的文本复制到剪贴板。

    代码实现:

    bulletPointAdder.py 

     1 import pyperclip
     2 
     3 text = pyperclip.paste()
     4 
     5 lst = text.split('
    ')        # 将字符串以
    为分隔符,分割成列表
     6 
     7 for i in range(len(lst)):
     8     lst[i] = '* ' + lst[i]      # 在列表的每个元素前加上'* '
     9 
    10 text = '
    '.join(lst)           # 将列表合成一个字符串
    11 
    12 pyperclip.copy(text)
    13 print(pyperclip.paste())
  • 相关阅读:
    Working with Deployment Configurations in CodeDeploy
    ECS 容器实例生命周期
    设置 API Gateway 金丝雀版本部署
    Elastic Beanstalk 滚动环境配置更新
    Kinesis Data Firehose 中的数据保护
    为 API Gateway REST API 资源启用 CORS
    高级 AWS Elastic Beanstalk 环境配置
    Amazon SWF Actors
    AWS CloudFormation 模板结构
    字符编码
  • 原文地址:https://www.cnblogs.com/FengZeng666/p/9743576.html
Copyright © 2020-2023  润新知