The replacement of the number X with a random number in an interval
-
This post is deleted! -
@terry-r Thank you for your response. I will try with the PythonScript plugin.
-
Random and unique doesn’t fit.
In your case it is a MUST that each replaced value is a UNIQUE number? -
@ekopalypse It is not necessary for each replaced to be unique, it may repeat once, twice.
-
from Npp import editor from random import randint editor.rereplace(r'\b740\b', lambda x: randint(10,20))
This would replace a value 740 with a random number from 10 to 20.
-
@ekopalypse Thank you a lot for the help! I have never until now used PythonScript, or any other plugin for Notepad++. If you could also tell me succinctly which are the steps on how I could implement the code such that it could do what I want, that would be wonderful.
-
the steps are
- Plugins->PythonScript->New script (save as dialog opens).
- Give the script a meaningful name and save it
- Copy the code as indicated into the newly created document and save it
- Open a file with the content you want to change and run
- Plugins->PythonScript->Scripts->YOUR_SCRIPT_NAME
If an error occurs, open the console (Plugins->PythonScript->Show Console) and see what it is complaining about.
-
@ekopalypse I am getting this error
ModuleNotFoundError: No module named 'Npp'
-
Did you try to run your script with your own python.exe? Or did you follow @Ekopalypse’s instructions, where you run it inside Notepad++'s PythonScript plugin, using the PythonScript menus? Because if you ran it with PythonScript and it couldn’t find the Npp module, something is seriously wrong with your PythonScript installation.
If you were really running from within PythonScript, please use Plugins > Python Script > Show Console, and give us a screenshot of that, including both the Python initialization and the error in the same screenshot. That might help us to give you ideas on how to fix your environment.
Other useful information to help with debug would be a screenshot of Plugins > Python Script > About, and maybe even your ?-menu’s Debug Info copied to clipboard and pasted here.
-
@peterjones Oh, you are perfectly right. I have begun to run the script with my own python.exe
It functioned perfectly what @Ekopalypse has told me. Likewise, I have had one more problem, but I have realised what I was doing wrong. When I was saving the script, I was saving it anywhere else other than in *\Notepad++\plugins\PythonScript\scripts and it was not showing up in my PythonScript script menu. I thank the two of you very much.