def add_unique_postfix(fn):
    fn = unicode(fn)
    
    if not os.path.exists(fn):
        return fn

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

    make_fn = lambda i: os.path.join(path, '%s__%d%s' % (name, i, ext))

    for i in xrange(2, sys.maxint):
        uni_fn = make_fn(i)
        if not os.path.exists(uni_fn):
            return uni_fn

    return None
__author__ = 'Denis Barmenkov <denis.barmenkov@gmail.com>'
dataset/ETHPy150Open hww712/knitter/knitter/common.py/add_unique_postfix