I have installed the PythonScript plugin for NP++ to program a script to be able to insert date and/or time. Based on example scripts I have created the following script :
import datetime
now = datetime.now()
timestr = now.strftime("%m/%d/%Y, %H:%M:%S")
editor.addText(timestr)
but this does not seem to work (trying to run it by going into the Extensions/Phythonscript/Scripts menu and clicking on the scripts name.
Even a simple script such as
Editor.addText("Test")
does not seem to have any effect.
Does anybody have any ideas as to what has gone wrong ? I have no experience in Python programming (but have programmed in other languages)
Cheers
Oliver
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Sasumner, you were correct, the following script is now working : import datetime
now = datetime.datetime.now()
timestr = now.strftime("%m/%d/%Y, %H:%M:%S")
editor.addText(timestr)
However I still have a problem when adding this script as a button, I get the following error :
An exception occirred due to plucin: DSpellCheck.dll Exception reason: Access violation
The button of the script appears actually beside the button of the DSpellChecker.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have installed the PythonScript plugin for NP++ to program a script to be able to insert date and/or time. Based on example scripts I have created the following script :
import datetime
now = datetime.now()
timestr = now.strftime("%m/%d/%Y, %H:%M:%S")
editor.addText(timestr)
but this does not seem to work (trying to run it by going into the Extensions/Phythonscript/Scripts menu and clicking on the scripts name.
Even a simple script such as
Editor.addText("Test")
does not seem to have any effect.
Does anybody have any ideas as to what has gone wrong ? I have no experience in Python programming (but have programmed in other languages)
Cheers
Oliver
it seems that datetime.now() does not exist as I get the following error :
'module' object has no attribute 'now'
I have also tried with datetime.today(), same error :
'module' object has no attribute 'today'
I have also exchanged the first line of the script with
from datetime import date
same error.
any help would be welcome
Cheers
Oliver
I searched the forum and found a script that does the trick :
import time
editor.addText(time.strftime('%d/%m/%Y '))
had found it here :
https://sourceforge.net/p/npppythonscript/discussion/1199074/thread/a50c6c37/
thanks to IObasetom
I think your original script would have worked (or been close to working) if you had done:
now = datetime.datetime.now()
Perhaps why it didn't appear to do anything is you didn't have the console showing to see the errors.
Thanks Sasumner, you were correct, the following script is now working :
import datetime
now = datetime.datetime.now()
timestr = now.strftime("%m/%d/%Y, %H:%M:%S")
editor.addText(timestr)
However I still have a problem when adding this script as a button, I get the following error :
An exception occirred due to plucin: DSpellCheck.dll Exception reason: Access violation
The button of the script appears actually beside the button of the DSpellChecker.
I don't know, I don't use DSpellCheck. Maybe remove it if you don't use it either. Also, maybe it is an older version, try looking for newer version.
@Sasumner I just disactiaved DSPellCheck and now it works great ;-) Thanks again for your help