def write_distances_file(handler, distances, clustering, distance_descriptors):
    
    for cluster in clustering.clusters:
        handler.write("cluster id, distance id, avg, std, elements in cutoff\n")
        for distance_id in distances:
            cluster_distances = distances[distance_id][cluster.all_elements]
            if "cutoff" in distance_descriptors[distance_id]:
                cutoff = float(distance_descriptors[distance_id]["cutoff"])
                print cluster_distances[cluster_distances < cutoff]
                handler.write("%s, %s, %.3f, %.3f, %d \n"%(cluster.id,
                                                           distance_id, 
                                                           numpy.mean(cluster_distances), 
                                                           numpy.std(cluster_distances),
                                                           len(cluster_distances[cluster_distances < cutoff])))
            else:
                handler.write("%s, %s, %.3f, %.3f \n"%(cluster.id,
                                                   distance_id, 
                                                   numpy.mean(distances[distance_id][cluster.all_elements]), 
                                                   numpy.std(distances[distance_id][cluster.all_elements])))
    
    handler.write("\n\n")
    
    for cluster in clustering.clusters:
        for distance_id in distances:
            handler.write("%s, %s, "%(cluster.id, distance_id) )
            for element in cluster.all_elements:
                handler.write((distances[distance_id][element])%"%.3f, ")
            handler.write("\n")
dataset/ETHPy150Open victor-gil-sepulveda/pyProCT/pyproct/postprocess/actions/proteinAtomDistances.py/write_distances_file/swapped operands of `%`