def unique_file(path, chmod=511, mode='w'):
 (path, tail) = os.path.split(path)
 return _unique_file(path, filename_pat=(lambda count: ('%04d_%s' % (count, tail))), count=0, chmod=chmod, mode=mode)

def unique_file ( path , chmod = 511 , mode = 'w' ) : ( path , tail ) = os . path . split ( path ) return _unique_file ( path , filename_pat = ( lambda count : ( '%04d_%s' % ( count , tail ) ) ) , count = 0 , chmod = chmod , mode = mode )
safely finds a unique file .