import bz2
import gzip


def must_open(filename,mode='r'):
    """
    Return file handle
    Deal multi-file type such as .gz .bz2
    """

    if filename.endswith('.gz'):
        fp = gzip.open(filename, mode)
    elif filename.endswith('.bz2'):
        fp = bz2.open(filename,mode)
    else:
        fp = open(filename, mode)

    return fp