import gzip


def openGzipOrText(fPath,encoding=None) :
    """Opens a file for reading as text, uncompressing it on read if the path ends in .gz"""
    if str(fPath).lower().endswith('.gz') :
        return gzip.open(fPath,'rt',encoding=encoding)
    else :
        return open(fPath,'rt',encoding=encoding)