I'm reading through an xml
file to find four bits of data that I'm then updating in a database. My question is how to more efficiently search for them. Is line by line the best in this case? I'm currently reading the whole file into a variable and then doing a search on it.
with open(cur_file, 'rb') as xml_file:
bill_mgr_email_re = re.compile(r'<BillingManagerInformation .* Email="(.*.com)"')
num_bills_re = re.compile(r'NumberBills="(\d+)"')
num_ebills_re = re.compile(r'NumberOfEbills="(\d+)"')
num_mailed_re = re.compile(r'NumberOfMailedDocs="(\d+)"')
data = xml_file.read()
bill_mgr_email = bill_mgr_email_re.search(data).group(1)
num_bills = num_bills_re.search(data).group(1)
num_ebills = num_ebills_re.search(data).group(1)
num_mailed = num_mailed_re.search(data).group(1)