/ Anzahl erhöhen Python - Python, Plugins, Notepad ++

Erhöhen Sie die Anzahl Python - Python, Plugins, Notepad ++

Tut mir leid, ich recherchiere ungefähr 1 Tag, finde aber keine Lösung.

Ich habe diesen Code und arbeite nicht

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

notepad.new()
editor.addText(content)

Ich möchte 10.000 Wörter in einer Datei mit einer erhöhten Anzahl ersetzen.

Beispiel

von:

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

zu:

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

Das gewünschte Wort ist printing-1, printing-2, print-3,... zu printing-10000.

Ich habe versucht, mit Python-Plugin in Notepadd ++ zu arbeiten, aber nicht funktioniert. Außerdem kenne ich den Option-Spalteneditor (Alt + C) in Notepad ++, aber ich kann keine 10.000 Wörter auswählen.

Wie kann ich diese Aufgabe mit Python in notepadd ++ bearbeiten?

Danke fürs Lesen

Antworten:

0 für die Antwort № 1

Ersetzen Sie Ihre while-Schleife durch Folgendes:

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

Ich brauche Hilfe, um den Code zu verstehen, fragen Sie einfach!