Community
    • Login

    Python script rereplace stops working

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 Posters 2.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bob MorleyB
      Bob Morley
      last edited by

      Have written a small python script that would do a regular expression replace on each line changing a Epoch timestamp to a nicely formatted date/time. This operation is intended for our log files, so these files can get up to 20MB in size. What I find is that from time to time on larger files the rereplace stops working and shows a number of “CRLF” markings in the file.

      Here is the script:

      import time
      def epoch_replace(m):
      return time.strftime(“%Y-%m-%d %H:%M:%S”, time.localtime(int(m.group(1)) + 978307200))

      editor.beginUndoAction()
      editor.rereplace(r"^([0-9]{9})", epoch_replace)
      editor.endUndoAction()

      Any idea on why this might be happening? I re-wrote it to apply the rereplace on “chunks” of the file, but it appeared to make no difference. Also no difference if I avoided the undo action. However, if you do the undo occasionally it crashes Notepad++.

      Any ideas?

      1 Reply Last reply Reply Quote 0
      • dailD
        dail
        last edited by

        Make sure you have periodic back ups turned off in the settings.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors