def get_open_file_object(fname_or_fobj, read_write="rw"):
    """Returns an open file object for either a file name or open file object."""
    openfile = not (
        hasattr(fname_or_fobj, "read") or hasattr(fname_or_fobj, "write")
    )
    if openfile:
        filename = fname_or_fobj
        f_obj = open(filename, read_write)
    else:
        f_obj = fname_or_fobj

    return f_obj