import gzip


def openfile(infile, method, compresslevel=1):
    """
    Open file handling if compressed or not
    """
    fhd = None

    if infile.endswith('.gz'):
        fhd = gzip.open(infile, method, compresslevel)

    else:
        fhd = open(infile, method + '+b')

    return fhd