나는 다음과 같은 텍스트가 :루프 나머지 요소
여기line, Error = 12, This is the Error
line, Error = 34, Another Error
line, Error = 90, Error Three
내가 가지고 얼마나 멀리입니다 :
theText = 'ERROR: ...'
ERROR_RE = re.compile(r'^ERROR: <(?P<path>.*):(?P<line>[0-9]+)> (?P<error>.*)$')
mainName = '\Main.ext'
# Go through each line
for fullline in theText.splitlines():
match = self.ERROR_RE.match(fullline)
if match:
path, line, error = match.group('path'), match.group('line'), match.group('error')
if path.endswith(mainName):
callSomething(line, error)
# else check next line for 'Call Trace:'
# check next lines for mainName and get the linenumber
# callSomething(linenumber, error)
ERROR: <C:\Includes\Library1.inc:123> This is the Error
Call Trace:
<C:\Includes\Library2.inc:456>
<C:\Includes\Library2.inc:789>
<C:\Code\Main.ext:12>
<Line:1>
ERROR: <C:\Includes\Library2.inc:2282> Another Error
Call Trace:
<C:\Code\Main.ext:34>
<C:\Code\Main.ext:56>
<C:\Code\Main.ext:78>
<Line:1>
ERROR: <C:\Code\Main.ext:90> Error Three
나는 다음과 같은 정보를 추출하고 싶습니다를
루프 내의 나머지 요소를 반복하는 비법은 무엇입니까?
솔루션 : http://codepad.org/BcYmybin
왜 오류 3은 나머지 오류와 일치하지 않습니까? –
죄송합니다, 명확하지 않습니다. errorText하지만 호출 추적에서 가장 가까운 Main.ext 파일의 줄 번호를 원합니다. 오류 3은 이미 Main.ext에서 발생했습니다 – Adamarla