I have the following script tha that gets the service_name of a tnsfiles if available if not it get the SID it seems to work fine but it is returning me tuples that I am unable to parse
#!/usr/bin/env python
import re
regexes = re.compile(r'SERVICE_NAME\s?=\s?(.+?)\)|SID\s?=\s?(.+?)\)')
with open('tnsnames.ora.test') as tns_file:
for tnsname in tns_file:
match = regexes.search(tnsname)
if match:
print(match.groups())
the script returns the following:
(None, 'db1')
('db2', None)
('db3', None)
but I only want to have the name of the db returned not the None
how can I strip the "None" from the output. i cannot use re.findall because there are some lines in the tnsnames that have a service_name and a sid and then I will have duplicates.
how can I parse the output of match regex object to ignore the none?