基本上我从https://en.wikipedia.org/wiki/List_of_lists_of_lists复制了一大堆列表到我的剪贴板中。 当我运行我的程序时,它会在每行之后添加项目符号。(Python)帮助修改剪贴板中的字符串
例如:
Lists of Iranian films
会转换成:
•• Lists of Iranian films ••
等等。该程序适用于在行之前添加子弹的情况,但当我将它们放在它之后时,它只打印一个不带任何换行符的长字符串。谁能告诉我我做错了什么?
下面的代码:
#bulletPointAdder.py - Adds Wikipedia bullet points to the start and end
#of each line of text on the clipboard
import pyperclip
text=pyperclip.paste() #paste a big string of text from clipboard into the 'text' string
# Separate lines and add stars
lines = text.split('\n') #'lines' contains a list of all the individual lines up until '\n'
#lines= ['list of iserael films', 'list of italian films' ...]
for i in range(len(lines)): #loop through all indexes in the "lines" list
lines[i] = '••' + lines[i] + '••' #add bullets before and after each line
text = '\n'.join(lines) #put a '\n' in between the list members (joins them) into a single string
pyperclip.copy(text)
在我的剪贴板:
List of Israeli films before 1960
List of Israeli films of the 1960s
List of Israeli films of the 1970s
List of Israeli films of the 1980s
剪贴板粘贴在记事本:
••List of Israeli films before 1960••••List of Israeli films of the 1960s••••List of Israeli films of the 1970s••••List of Israeli films of the 1980s••
你的问题是什么?什么是“文字”的类型?它是'str'元素的'list'吗? – blacksite
对不起,这个类型是一个复制到剪贴板的字符串。 – tadm123