How to install and run a script in Python Script?
-
@PeterJones There Is no Python script in the drop down options
-
@dr-ramaanand said in How to install and run a script in Python Script?:
There Is no Python script in the drop down options
A screenshot would have been really helpful. Because if I open up a 32bit Notepad++, I do see it there.
But my guess is that if you don’t see it in the Available tab, it’s probably in the Installed tab, like this screenshot from my normal-use Notepad++:
And if it’s not on either of those tabs, check the Updates or Incompatible tabs (though it shouldn’t be on the Incompatible tab).
If it’s already installed, you don’t need to install it again. Step 0 in the instructions is only there for " if you don’t have it already". If you do have it already, you can skip step 0.
-
@PeterJones
is what is shown in the “Available” dropdown and
is what is shown in the installed dropdownThe updates dropdown is blank!
-
Please share your ?-menu’s Debug Info. Without knowing what version of Notepad++ you are using, we cannot replicate your problem.
Your Plugins Admin screenshot shows your Notepad++ version is way out of date: it’s missing the Plugin List Version in the lower-right corner – which was added in v8.4.6 in the Fall of 2022. Are you seriously on a version of Notepad++ that’s more than 1.5 years out of date?
That said, PythonScript plugin was available even back then [plugin version 2.0.0 was released in Feb 2022] – so there may be something even more wrong with you installation than just the ancient revision. But until you tell us more about your out-of-date Notepad++ installation (Debug Info), we cannot begin to try to replicate your non-standard setup to see what is going wrong for you.
-
@PeterJones When I try to update Notepad++, I get this error:-
This is the DeBug Info:-
OK,I uninstalled and re-installed Notepad++ and this is the new DeBug Info:-
I was now able to install the Python Script!
However, I’m still unable to Update Notepad++. The first screenshot shows what error is being shown as a pop-up! -
@PeterJones Now how do I do Plugins > Python Script > Context-Help, then choose Editor Object, and go to the editor.rereplace() section ?
How do I add this script and run it ?:-# encoding=utf-8 from Npp import * def custom_replace_func(m): new_text = "zone_{}".format(custom_replace_func.counter) custom_replace_func.counter += custom_replace_func.increment return new_text custom_replace_func.counter = 1 # starting value custom_replace_func.increment = 1 editor.rereplace(r'zone_(\d+)', custom_replace_func)
I’m trying to replace
<sup>[0]</sup>
with<sup>[1]</sup>
and renumber the rest as<sup>[2]</sup>
,<sup>[3]</sup>
,<sup>[4]</sup>
,<sup>[5]</sup>
,<sup>[6]</sup>
,<sup>[7]</sup>
and so on, so I should probably tweak your script to:-# encoding=utf-8 from Npp import * def custom_replace_func(m): new_text = "<sup>[{}".format(custom_replace_func.counter) custom_replace_func.counter += custom_replace_func.increment return new_text custom_replace_func.counter = 1 # starting value custom_replace_func.increment = 1 editor.rereplace(r'<sup>[(\d+)', custom_replace_func)
-
@Mark-Olson I’ve seen your posts about using the Python Script. Peter might be busy, so maybe you can help?
-
@dr-ramaanand said,
@Mark-Olson I’ve seen your posts about using the Python Script. Peter might be busy, so maybe you can help?
Have a bit of patience. There is no guaranteed response time. We are all just fellow Notepad++ users, none of us are employed by Notepad++ , and so we are not paid to help each other, and we all have lives outside of this forum. If you don’t get a reply within a day or two, then it makes sense to ping again to see if anyone else can join in. If it’s only a matter of minutes or hours that you are left waiting, it just means you need to be patient.
editor.rereplace(r'<sup>[(\d+)', custom_replace_func)
That regex wouldn’t work to match
<sup>[1
in a Notepad++ regular expression, so I’m not sure why you think that it would work to match that same text in a PythonScript regular expression. The bracket[
is special to most regex engines, so you have to escape it, like\[
-----
regarding your installation problems: my guess is it’s a permissions issue or a Win7 issue.
-
You might have to download and run the installer by right clicking and saying “run as administrator” while Notepad++ is not running, rather than trying to just use the ? > Update Notepad++ command inside Notepad++.
-
And you are on Windows 7, which per official “SUPPORTED OS” list is NOT a supported OS for Notepad++ anymore. It should still work, but the developer does not test on Win7, and does not guarantee on Win7; you use Win7 to your own risk. (Microsoft says the same thing: Win7 is no longer supported by its creator! That should tell you something.)
-
Addendum: The error you are showing is a TLS issue, which is website security (https://) problem. It may be that Windows 7 doesn’t have the necessary libraries to safely download from a modern https:// website. In which case, my earlier suggestion of manually downloading the installer (from https://notepad-plus-plus.org/downloads/) and running it manually rather than through the Notepad++ ?-menu’s Update Notepad++ action might be your only choice.
-
-
@PeterJones OK, so how do I do Plugins > Python Script > Context-Help, then choose Editor Object, and go to the editor.rereplace() section ?
How do I add this script and run it ?:-# encoding=utf-8 from Npp import * def custom_replace_func(m): new_text = "<sup>\[{}".format(custom_replace_func.counter) custom_replace_func.counter += custom_replace_func.increment return new_text custom_replace_func.counter = 1 # starting value custom_replace_func.increment = 1 editor.rereplace(r'<sup>\[(\d+)', custom_replace_func)
I’m trying to replace
<sup>[0]</sup>
with<sup>[1]</sup>
and renumber the rest as<sup>[2]</sup>
,<sup>[3]</sup>
,<sup>[4]</sup>
,<sup>[5]</sup>
,<sup>[6]</sup>
,<sup>[7]</sup>
and so on -
@dr-ramaanand said in How to install and run a script in Python Script?:
@PeterJones OK, so how do I do Plugins > Python Script > Context-Help, then choose Editor Object, and go to the editor.rereplace() section ?
I still am not sure what you intend by this sentence – that instruction isn’t in the FAQ,
so I’m not sure where you’re getting it (unless it’s from the actual script that you’re trying to install).Update: I did some more searching: that was a line from the mathematical replacement FAQ; the next paragraph below correctly interprets my sentence from that second FAQIt is literally telling you: click the Plugins menu, click PythonScript then click Contenxt-Help, then go click on the Editor Object, then search the page for
editor.rereplace
, and you will find the help so that you can learn more about theeditor.rereplace()
command. Addendum: That was not part of the instructions on how to run it; that was part of the instructions on how to learn more about the commands involved, so that you can learn during the experience, and learn how to customize the example scripts, because we aren’t going to always spoonfeed you.How do I add this script and run it ?:-
I’m trying to replace<sup>[0]</sup>
with<sup>[1]</sup>
and renumber the rest as<sup>[2]</sup>
,<sup>[3]</sup>
,<sup>[4]</sup>
,<sup>[5]</sup>
,<sup>[6]</sup>
,<sup>[7]</sup>
and so onYour script looks like it’s a good starting place, based on the example scripts you copied it from.
Then follow the instructions from the FAQ to create a new script, giving it a meaningful name, paste your script which you just showed into it, save it, and run it. The FAQ gives step-by-step, point-by-point instructions for how to do this, and I cannot say it any better than it’s already described in the FAQ.
----
Please note: This Community Forum is not a data transformation or free-code-writing service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and the problem can be easily solved with a regular expression, we’ll likely give you a start on that. And if it requires scripting (more complex logic than can easily be done in a regular expression), we will let you know. If your problem catches the interest of one of the regulars, that person may even provide an example script that may be helpful; often times, we might even ask you to search the forum for a particular term, because that term will likely help you find a script that already implements something similar. Whether it’s a previously-written script, or whether one of us hacks something up for you specifically, it won’t always exactly match your problem, but it’s at least a starting point for you to work from. At that point, you are expected to take the lead, and make any changes to the example that are necessary to convert it from what was provided to something that meets you exact needs. This forum is focused on Notepad++; while you may want to use Notepad++ for the implementation, text editors aren’t always the right tool for complex text transformation tasks: since you are seeing this boilerplate in my reply, it means that I believe that it’s essentially a generic programming challenge, which is off topic for a Notepad++-specific forum.
-
@PeterJones I couldn’t do it on that system, so I tried doing it from my other laptop, but I am getting this error:-
This is the DeBug Info of the other laptop which I’m trying to use now:-
-
I have no clue how you made it do that – sounds like you’ve done some strange configuration to your Windows 7 setup to get it to give an error like that. Just open
c:\program files\notepad++\plugins\PythonScript\doc\index.html
in your favorite browser and use that for referencing the PythonScript documentation instead of using the menu option.But just so we are clear: Reading the documentation to see the original source of the
add_1
script has nothing to do with running the script. The FAQ: How to Install and Run A Script in PythonScript tells you the step-by-step instructions for how to install and run the script. I think you need to focus on that, before trying to read the documentation and see where the script was derived from.Also, to be clear: if you have more difficulty in trying to follow the instructions and trying to get the script to run, you’ll have to hope that someone else here will be able to reply, because I’ve given you as much information as I can. Good luck.
-
@PeterJones said in How to install and run a script in Python Script?:
FAQ: How to Install and Run A Script in PythonScript
In the above, I think point no.1. Create a new script should mention, “script” directory, not, “user script” directory
-
@dr-ramaanand said in How to install and run a script in Python Script?:
@PeterJones said in How to install and run a script in Python Script?:
FAQ: How to Install and Run A Script in PythonScript
In the above, I think point no.1. Create a new script should mention, “script” directory, not, “user script” directory
It should not. The “user script” directory is well defined in the FAQ.
That superscript ¹ is a clickable footnote. And if you follow that click, it goes to
I circled the relevant section for you. I hope this helps.
-
@PeterJones Yes, that helped. Thanks! I did all that was asked to be done in that FAQ. Now how to Renumber every <sup>followed by a number, starting with 1 in my file?
-
@dr-ramaanand said in How to install and run a script in Python Script?:
I did all that was asked to be done in that FAQ. Now how to Renumber …
The “USAGE” section in the FAQ explains how to run the script.
-
@PeterJones I did that and got this result:-
I think I now got to go and remove the\
before the[
bracket from my file in the user script directory
Is there a way to edit that or should I create a new script?
Of course, the easiest way around this is to find<sup>\
and replace it with<sup>
Unfortunately, I am unable to find<sup>\
in either the Normal mode or the Regular Expression mode -
Hopefully someone else will be able to help you. I’ve spent as much time on this as I can. Again, good luck.
-
@PeterJones OK, thanks a lot! “
<sup>.*?\[
” finds what I want it to find, that is “<sup>\[
” with the Regular expression mode turned on. I then put “<sup>[
” in the Replace with field and hit “Replace all” -
-