The purpose of this function is to determine if report_input_file
is either in JSON format or XML format, this is what I came up with, just want to know if this is best practice / pythonic way of achieving this?
def parse_report_file(self, report_input_file):
""" Checks if input report file is of type json or xml """
parsed_report_file = None
try:
parsed_report_file = self._parse_json_file(report_input_file)
self.is_json_report_file = True
except Exception, e:
parsed_report_file = self._parse_xml_file(report_input_file)
self.is_json_report_file = False
return parsed_report_file
if(s.startswith('<')
wheres
is the first in your file. An XML document entity (in common parlance, an XML document) must start with<
. – Dex' ter Aug 5 at 13:10try-catch
for cases where thereport_input_file
is on neither of these two formats. – JonB Aug 5 at 13:15