Search code examples
pythonstringopenpyxluppercaselowercase

Python allow accepting two strings depends on cases


I found the error when I read excel using openpyxl library that the library reads '[Content_Types].xml' while all my .xlsx files to read contains '[content_types].xml'.

The library calls the file by string ARC_CONTENT_TYPES = '[Content_Types].xml' and read the file by

def read_manifest(self):
    src = self.archive.read(ARC_CONTENT_TYPES)
    root = fromstring(src)
    self.package = Manifest.from_tree(root)

I would like to change it to accept both '[Content_Types].xml' and '[content_types].xml' so that the library can accept both cases.

Will there be any helpful tips or any other methods to solve my issue?


Solution

  • Almost a year ago and I forgot to put how I managed it. I basically fixed the related python library so that it can accept both cases by putting 'if ... else ...' condition into the library.

    if xmlstring.startswith('c'):
        ARC_CONTENT_TYPES = '[content_Types].xml'
    else:
        ARC_CONTENT_TYPES = '[Content_Types].xml'