I am seeing some solutions using re, out there on the Interwebs, but not what I want. I want to match several strings with partial content of a list item.
# as an example of one of the rows in a csv file
hostlist=[192.168.10.17, postgres12, "Red Hat 4.3", "broken"]
#pseudocode
if hostlist[2] contains "Red Hat" or "Debian" or "Fedora" or "Linux"
print(hostlist)
rowEdit=[hostlist[2], hostlist[0]]
The next few lines looked like a fruitful path, but it is not writing anything to csv:
rappos=row[4]
print(rappos)
match = re.search('Linux', rappos)
print(match)
if match==True:
print(rowEdit) #rowEdit is a subset of the list 'row'
writer.writerow(rowEdit)
#output
Red Hat Enterprise Linux ES 3
(<_sre.SRE_Match object at 0x7f58b78c44a8>, ' is a match')
Red Hat Enterprise Linux ES 3
(<_sre.SRE_Match object at 0x7f58b78c49f0>, ' is a match')
Red Hat Enterprise Linux ES 3
(<_sre.SRE_Match object at 0x7f58b78c4a58>, ' is a match')
Red Hat Enterprise Linux ES 3
(<_sre.SRE_Match object at 0x7f58b78c4988>, ' is a match')
Red Hat Enterprise Linux ES 3
(<_sre.SRE_Match object at 0x7f58b78c49f0>, ' is a match')
Windows Server 2003 Service Pack 2
(None, ' is a match')
Windows Server 2003 Service Pack 2
(None, ' is a match')
Windows Server 2003 Service Pack 2
(None, ' is a match')
Windows Server 2003 Service Pack 2
(None, ' is a match')
Windows Server 2003 Service Pack 2
(None, ' is a match')
Windows Server 2003 Service Pack 2
(None, ' is a match')
So should I be saying
if match != "None":
print(whatever)
The above if condition worked...
But I am not seeing the csv.writerow(rowEdit) function writing a csv file.
The https://github.com/wolf29/csv-edit/blob/master/reader3.py file is the real current code on this. I am getting the example code here a little messed up.