Hello,
I need to jump to a given string in a text file, and grab everything from that point to the end of the file for further processing using a regex.
I'm not sure why Python isn't happy:
I've also tried to open the file in binary mode, but get the same error:
Thank you.
I need to jump to a given string in a text file, and grab everything from that point to the end of the file for further processing using a regex.
I'm not sure why Python isn't happy:
with open(INPUTFILE,encoding="utf-8") as reader:
content = reader.read()
content = re.search(content,'^SessionData.+',re.MULTILINE|re.DOTALL)
c:\temp>list.files.py
Traceback (most recent call last):
File "C:\list.files.py", line 10, in <module>
content = re.search(content,'^SessionData.+',re.MULTILINE|re.DOTALL)
File "C:\Python38-32\lib\re.py", line 201, in search
return _compile(pattern, flags).search(string)
File "C:\Python38-32\lib\re.py", line 304, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Python38-32\lib\sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
File "C:\Python38-32\lib\sre_parse.py", line 948, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Python38-32\lib\sre_parse.py", line 443, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "C:\Python38-32\lib\sre_parse.py", line 554, in _parse
code1 = _class_escape(source, this)
File "C:\Python38-32\lib\sre_parse.py", line 349, in _class_escape
raise source.error('bad escape %s' % escape, len(escape))
re.error: bad escape \T at position 1494 (line 76, column 27)Here's an example of what is found in the intput file:FilePath = C:\Temp\SomeFile.txtIs it because Python interprets \T as a wrongly formated tab sequence?
I've also tried to open the file in binary mode, but get the same error:
with open(INPUTFILE,"rb") as reader:What would be the right way to extract part of a file for further parsing?
Thank you.
