import lzma


def open_dispout(dispout):
    """Open dispout file for writing.

    Args:
        dispout (str): dispout filename (disp.dat.xz)

    Returns:
        dispout (obj): file object

    """
    if dispout.endswith('.xz'):
        dispout = lzma.open(dispout, 'wb')
    else:
        dispout = open(dispout, 'wb')

    return dispout