def raise_cannot_open(path):
    """
    Raise an exception saying we can't open `path`.

    Parameters
    ----------
    path : str
        The path we cannot open
    """
    pieces = path.split('/')
    for i in xrange(1, len(pieces) + 1):
        so_far = '/'.join(pieces[0:i])
        if not os.path.exists(so_far):
            if i == 1:
                if so_far == '':
                    continue
                reraise_as(IOError('Cannot open ' + path + ' (' + so_far +
                           ' does not exist)'))
            parent = '/'.join(pieces[0:i - 1])
            bad = pieces[i - 1]

            if not os.path.isdir(parent):
                reraise_as(IOError("Cannot open " + path + " because " +
                           parent + " is not a directory."))

            candidates = os.listdir(parent)

            if len(candidates) == 0:
                reraise_as(IOError("Cannot open " + path + " because " +
                           parent + " is empty."))

            if 100 > len(candidates):
                # Don't attempt to guess the right name if the directory is
                # huge
                reraise_as(IOError("Cannot open " + path + " but can open " +
                                   parent + "."))

            if os.path.islink(path):
                reraise_as(IOError(path + " appears to be a symlink to a "
                                   "non-existent file"))
            reraise_as(IOError("Cannot open " + path + " but can open " +
                       parent + ". Did you mean " + match(bad, candidates) +
                       " instead of " + bad + "?"))
        # end if
    # end for
    assert False
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/utils/serial.py/raise_cannot_open/swapped operands of `>`