Monday, 15 February 2010

Using Python to Remove All Lines Matching Regex -


I am trying to remove all the lines where my regex matches (regex just searching for any row In which it has Yahoo!). import reile inputfile = open (

'c: \\ temp \\ script \\ remove.txt', 'w', encoding = "utf8") I get the following error:

Tracebacks (most recent call final): line 170, sub returned _compile (pattern, flags) .sub (repl, string, count) TypeError: expected string or buffer

If you want to modify the original file, use the fileinput module:

  importin fileinput .input (r'C: \ temp \ lip If not re.search (r '\ byahoo \ b', line): print line,    

No comments:

Post a Comment