增加Python的数量

增加Python的数量,python,plugins,notepad++,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字 范例 发件人: 致: 所需的

很抱歉,我研究了大约1天,但我没有找到解决方案

我有这个代码,但不工作

number = 1
content = editor.getText()
while "printing" in content:
    content = content.replace("printing", "printing-")
    number += 1

notepad.new()
editor.addText(content)
我想用递增的数字替换文件中的10.000字

范例

发件人:

致:

所需的单词是,
printing-1,
printing-2,
print-3,
。。。到
打印-10000

我在notepad++中尝试了python插件,但没有成功,我也知道notepad++中的选项列编辑器(alt+c),但我无法选择10.000个单词

?如何在notepadd++中使用python处理此任务


感谢阅读

用以下内容替换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

我想你需要帮助理解代码,尽管问吧

用以下内容替换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

我想你需要帮助理解代码,尽管问吧

“不工作”是什么意思?
content=content.replace(“打印”,“打印-”+str(数字))
问题是所有的替换词都是:printing-1,printing-1,printing-1。。。应该是,打印-1,打印-2,打印-3。。。等等。我用你写的最后一个代码进行测试,结果是一样的。“不工作”是什么意思?
content=content.replace(“printing”,“printing-”+str(number))
问题是所有替换词都是:printing-1,printing-1,printing-1。。。应该是,打印-1,打印-2,打印-3。。。等等。我用你上次写的代码测试,结果是一样的。你能解释一下为什么它不工作吗?我有点不确定你的问题。嗨,马基,谢谢你的支持。问题是所有替换词都是:printing-1,printing-1,printing-1。。。应该是,打印-1,打印-2,打印-3。。。等等。我用你上次写的代码测试,结果是一样的。我想用一个增加的数字替换一个简单的文件。很抱歉给你提供了错误的代码,我将研究一个解决方案。希望很快!检查答案,我用正确的代码更新了它,所以现在它应该可以工作了。再一次,如果你有任何问题,尽管问!谢谢你给我一个很好的挑战!祝你有美好的一天,愿上帝保佑!如果我的解决方案奏效,如果你能接受我的回答,我将不胜感激。非常感谢。你能解释一下为什么它不起作用吗?我有点不确定你的问题。嗨,马基,谢谢你的支持。问题是所有替换词都是:printing-1,printing-1,printing-1。。。应该是,打印-1,打印-2,打印-3。。。等等。我用你上次写的代码测试,结果是一样的。我想用一个增加的数字替换一个简单的文件。很抱歉给你提供了错误的代码,我将研究一个解决方案。希望很快!检查答案,我用正确的代码更新了它,所以现在它应该可以工作了。再一次,如果你有任何问题,尽管问!谢谢你给我一个很好的挑战!祝你有美好的一天,愿上帝保佑!如果我的解决方案奏效,如果你能接受我的回答,我将不胜感激。非常感谢。
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