/ / Augmenter le nombre Python - python, plugins, notepad ++

Augmenter le nombre Python - python, plugins, notepad ++

Désolé, je recherche environ 1 jour, mais je ne trouve pas la solution.

J'ai ce code et ne travaille pas

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

notepad.new()
editor.addText(content)

Je veux remplacer 10 000 mots dans un fichier avec un nombre croissant.

Exemple

de:

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

Le mot désiré est, printing-1, printing-2, print-3,... à printing-10000.

J'ai essayé avec le plugin python dans notepadd ++ mais je ne travaillais pas, je connais également l’éditeur de colonnes d’option (alt + c) dans notepad ++ mais je ne peux pas sélectionner 10 000 mots.

Comment puis-je traiter cette tâche avec Python dans Notepadd ++?

Merci d'avoir lu

Réponses:

0 pour la réponse № 1

Remplacez votre boucle while par ceci:

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

Si vous avez besoin d’aide pour comprendre le code, il suffit de demander!