Skip to main content
added 136 characters in body
Source Link
Janne Karila
  • 10.4k
  • 20
  • 34
  • It's not 100 % clear what exceptions you expect, but I presume you are trying to handle the case when the regex does not match. I suggest handling it this way:

          #Transformation #1
          match = re.match(pattern, inword)
          result = match.group() if match else None
    
  • "after processing a few files, the script slows down" Have you considered the possibility that a particular file, or even a particular line is slow to process? A possible explanation to your program suddenly slowing down isthat would be that regexes can suffer from catastrophic backtracking.

  • It's not 100 % clear what exceptions you expect, but I presume you are trying to handle the case when the regex does not match. I suggest handling it this way:

          #Transformation #1
          match = re.match(pattern, inword)
          result = match.group() if match else None
    
  • A possible explanation to your program suddenly slowing down is that regexes can suffer from catastrophic backtracking.

  • It's not 100 % clear what exceptions you expect, but I presume you are trying to handle the case when the regex does not match. I suggest handling it this way:

          #Transformation #1
          match = re.match(pattern, inword)
          result = match.group() if match else None
    
  • "after processing a few files, the script slows down" Have you considered the possibility that a particular file, or even a particular line is slow to process? A possible explanation to that would be that regexes can suffer from catastrophic backtracking.

Source Link
Janne Karila
  • 10.4k
  • 20
  • 34

  • It's not 100 % clear what exceptions you expect, but I presume you are trying to handle the case when the regex does not match. I suggest handling it this way:

          #Transformation #1
          match = re.match(pattern, inword)
          result = match.group() if match else None
    
  • A possible explanation to your program suddenly slowing down is that regexes can suffer from catastrophic backtracking.