这是一个愚蠢的问题,因此当我在网上搜索时,只找到了更高级问题的答案。
OK,所以我做了一个脚本:bulletPointAdder.py
在记事本中,我有一个列表(每行一个项目)。
如何将制作的脚本应用于记事本文件?
(该脚本按预期工作,因为我使用的是Al Stweigart撰写的“使用Python自动化无聊的东西-但是书没有帮助,或者我无法理解)”
#! python3
# bulletPointAdder.py - Adds Wikipedia bullet points to the start
# of each line of text on the clipboard.
import pyperclip
text = pyperclip.paste()
# Separate lines and add stars.
lines = text.split('\n')
for i in range(len(lines)): # loop through all indexes in the "lines" list
lines[i] = '* ' + lines[i] # add star to each string in "lines" list
text = '\n'.join(lines)
pyperclip.copy(text)
在此代码中,您使用了一个库“ pyperclip”,该库将把剪贴板中的文本(当您复制ctrl + insert时)获取为变量“ text”。
然后将'text'拆分为行列表,因为'\ n'表示行尾。
然后(缩进错误:“ for”行应与前几行一样位于缩进处),代码将以i索引的每一行(因为len(lines)是列表“ lines”的长度)并添加到每个元素i列表“行”中的字符串“ *”
现在,循环之外,变量“文本”成为一个字符串,该字符串合并了“行”行列表中的所有新元素
最后,pyperclip.copy(因此它需要在库“ pyperclip”中定义的函数“ copy”)将字符串复制到剪贴板中。
import pyperclip # a librairy of function that allows you communicating with the clipboard
text = pyperclip.paste() # takes the string from the clipboard
and add stars.
lines = text.split('\n') # Separate the text into a list of lines
for i in range(len(lines)): # loop through all elements of the list in the "lines" list using the index 'i'
lines[i] = '* ' + lines[i] # merges a star and a space behind the previous line of text. For each line i of 'lines', add '* '
text = '\n'.join(lines) # merges all elements of the list 'lines' into a string
pyperclip.copy(text) # export the string 'text' to the clipboard
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句