def unique_filename(filename, limit=maxsize):
    if not os.path.exists(filename):
        return filename

    path, name = os.path.split(filename)
    name, ext = os.path.splitext(name)

    def make_filename(i):
        return os.path.join(path, '%s_%d%s' % (name, i, ext))

    for i in xrange(1, limit):
        unique_filename = make_filename(i)
        if not os.path.exists(unique_filename):
            return unique_filename

    try:
        raise FileExistsError()
    except __HOLE__:
        raise IOError(errno.EEXIST)
dataset/ETHPy150Open nils-werner/zget/zget/utils.py/unique_filename