增加Python数量

时间:2016-02-15 12:24:48

标签: python plugins notepad++

对不起,我研究了大约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处理此任务?

感谢您阅读

1 个答案:

答案 0 :(得分:0)

用这个替换你的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

我需要帮助才能理解代码!