Tim Finley wrote: > I get the following when running a script. > > TypeError: argument 1 must be string or read-only character buffer, not > _sre.SRE_Pattern > > Here is the script I am trying to run. I am trying to verify that my > search is returning what I am trying to search for, but due to the error > I can verify it. > > import re > > log = open('audit.log') # Opens audit log > log2 = open('timaudit.log','w') > for line in log: > line =re.compile(r"""
Here you are replacing 'line' the data from one line of the log with 'line' a compiled regular expression. 'line' the data is no longer available. > \w #match any alphanumeric character > \Audit report for user+ > \User reported as inactive+ > """, re.VERBOSE) > line.search('Audit report for user () User reported as inactive') Now you use 'line' the regex to search some fixed text. > log2.write(line) This writes the regex to the file, which is the cause of the error. > > log.close() > log2.close() I'm not really sure what you are trying to do. I think you want to write every line from log that matches the regex to log2. Code to do that would look like this: log = open('audit.log') # Opens audit log log2 = open('timaudit.log','w') audit_re =re.compile(r""" \w #match any alphanumeric character \Audit report for user+ \User reported as inactive+ """, re.VERBOSE) for line in log: if audit_re.search(line): log2.write(line) log.close() log2.close() Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor