Menu

A small script to insert date and/or time

Help
Oliver
2019-04-29
2019-05-07
  • Oliver

    Oliver - 2019-04-29

    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

     
  • Oliver

    Oliver - 2019-04-29

    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

     
  • Oliver

    Oliver - 2019-04-29

    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

     
    • Sasumner

      Sasumner - 2019-04-29

      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.

       
      • Oliver

        Oliver - 2019-04-29

        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.

         
        • Sasumner

          Sasumner - 2019-04-30

          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.

           
          • Oliver

            Oliver - 2019-05-07

            @Sasumner I just disactiaved DSPellCheck and now it works great ;-) Thanks again for your help

             

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.