Community
    • Login

    Python script rereplace stops working

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 Posters 2.5k Views 2 Watching
    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 Offline
      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 Offline
        dail
        last edited by

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

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors