很抱歉,我研究了大约1天,但我找不到解决方案。
我有这个代码,但是不能工作
number = 1
content = editor.getText()
while "printing" in content:
content = content.replace("printing", "printing-")
number += 1
notepad.new()
editor.addText(content)我想用递增的数字替换文件中的10.000个单词。
示例
发自:
Lorem Ipsum is simply dummy text of the printing
Other example text is simply from user any
Lorem Ipsum is simply dummy text of the printing
Other example text is simply from user roger
Lorem Ipsum is simply dummy text of the printing
Other example text is simply from user milton至:
Lorem Ipsum is simply dummy text of the printing-1
Other example text is simply from user any
Lorem Ipsum is simply dummy text of the printing-2
Other example text is simply from user roger
Lorem Ipsum is simply dummy text of the printing-3
Other example text is simply from user milton想要的词是,printing-1, printing-2, print-3,...敬printing-10000。
我试过在notepadd++中使用python插件,但不能工作,我也知道notepad++中的列编辑器(alt+c)选项,但我不能选择10.000个单词。
如何在notepadd++中使用python处理此任务?
感谢您的阅读
发布于 2016-02-15 20:43:10
用下面的代码替换您的while循环:
split_content = content.split("\n") #split content into sentences by the newline
new_content = ""
for sentence in split_content: #split sentence into words
for word in sentence.split(" "):
if word == "printing":
new_content += "printing-%s " % (number)
number += 1
else:
new_content += word + " "
new_content += "\n" #put newlines back in to keep original formatting如果你需要帮助理解代码,尽管问吧!
https://stackoverflow.com/questions/35409333
复制相似问题