Using regexp I am searching through text file which contains data. I get output similar to this. Here's what I get for example:
36
37
36
36
36
76
39
36
68
36
56
36
36
36
...
I need all those 36 to be in array like this [ '36', '36', .... ] The sample code is below.
#!/usr/bin/python
import re
log = re.compile('Deleted file number: first: (\d+), second (\d+), third (\d+), fourth (\d+), bw (\d+), value: ([\dabcdefx]+), secondvalue: ([\d.]+)LM, hfs: ([\d.-]+)ls')
logfile = open("log.txt", "r").readlines()
List = []
for line in logfile:
m = log.match(line)
if m:
first = int (m.group(1))
second = int (m.group(2))
third = int (m.group(3))
fourth = int (m.group(4))
bw = int (m.group(5))
value = int (m.group(6),0)
secondvalue = float (m.group(7))
hfs = float (m.group(8))
List.append(str(first)+","+str(second)+"," \
+str(third)+","+str(fourth)+"," \
+str(bw)+","+str(value)+"," \
+str(secondvalue)+","+str(hfs))
for result in List:
print(result)
I can use sys.stdout.write() to display it in one single line same with print item, But how can I put all this into one array to be like array = [ "149", 149", "153", "153" and so on]
Any help would be appreciated.