I have text file below:
Is there any way to do removing the empty list while using re.findall
Started : Sunday, May 1, 2016 1:59:16 PM
Source : C:\RegularExpressionsWithDotNet\robocopytest\source\தமிழ்\हिन्दी\English
Dest : C:\RegularExpressionsWithDotNet\robocopytest\destn\
Started : Sunday, May 1, 2016 1:59:16 PM
Source : C:\RegularExpressionsWithDotNet\robocopytest\source\தமிழ்\हिन्दी\English
Dest : C:\RegularExpressionsWithDotNet\robocopytest\destn\
My Code is below:
with open(r'C:\debug.log', 'r', encoding='utf-8') as fr:
eachline = fr.read()
data = [eachline.strip() for eachline in eachline.splitlines()]
datalinelist = []
for i in data:
datalinelist.append(re.findall(r'\bSource : (.+)', i))
datalinelist
My Out is [[], ['C:\\RegularExpressionsWithDotNet\\robocopytest\\source\\தமிழ்\\हिन्दी\\English'], [], [], ['C:\\RegularExpressionsWithDotNet\\robocopytest\\source\\தமிழ்\\हिन्दी\\English'], []]
Is there any way to do removing the empty list while using re.findall
If i am doing [line for line in open(file,'r',encoding='utf-8') if re.findall(r'Source : .+',line)]
I am getting proper out ['Source : C:\\RegularExpressionsWithDotNet\\robocopytest\\source\\தமிழ்\\हिन्दी\\English\n', 'Source : C:\\RegularExpressionsWithDotNet\\robocopytest\\source\\தமிழ்\\हिन्दी\\English\n']
What is the error in processing with condition
from How to apply re.findall to a file giving empyt list
No comments:
Post a Comment