Ask Your Question

Revision history [back]

That's already pretty short. Here is an alternative one-liner using graphs_list.to_graph6 and print:

sage: print(graphs_list.to_graph6(L), file=open('matching_graphs.g6', 'w'), end='')

This builds a big string in memory though, so it wouldn't be suitable for gigantic lists.

We could also mimic Mathematica by defining a somewhat generic export function:

def export(filename, object_list, method_name):
    with open(filename, 'w') as f:
        for obj in object_list:
            f.write(attrcall(method_name)(obj) + '\n')

Then we can do:

sage: export('matching_graphs.g6', L, 'graph6_string')