I'm trying to use a regex in Python to match a file (saved as a string, ie "/volumes/footage/foo/bar.mov") to a log file I create that contains a list of files. But when I run the script, it gives me this error: sre_constants.error: unbalanced parenthesis
. The code I'm using is this:
To read the file:
theLogFile = The_Root_Path + ".processedlog"
if os.path.isfile(theLogFile):
the_file = open(theLogFile, "r")
else:
open(theLogFile, 'w').close()
the_file = open(theLogFile, "r")
the_log = the_file.read()
the_file.close()
Then inside a for
loop I reassign (I didn't realize I was doing this until I posted this question) the the_file
variable as a string from a list of files (obtained by running through a folder and it's subsets and grabbing all the filenames), then try to use regex to see if that filename is present in the log file:
for the_file in filenamelist:
p = re.compile(the_file, re.IGNORECASE)
m = p.search(the_log)
Every time it hits the re.compile()
part of the code it spits out that error. And if I try to cut that out, and use re.search(the_file, the_log)
it still spits out that error. I don't understand how I could be getting unbalanced parenthesis from this.