ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 04 Dec 2012 13:04:05 -0600How to get a graph back from canonical_label graph6_stringhttp://ask.sagemath.org/question/9606/how-to-get-a-graph-back-from-canonical_label-graph6_string/I have a list of graphs that I take their canonical_label 's graph6_string and then I save that list to a file.
Now I want to open that file and get sage graphs from the list of canonical_label graph6_string
How can I do it?
Thank you!Tue, 04 Dec 2012 08:46:46 -0600http://ask.sagemath.org/question/9606/how-to-get-a-graph-back-from-canonical_label-graph6_string/Answer by fidbc for <p>I have a list of graphs that I take their canonical_label 's graph6_string and then I save that list to a file.</p>
<p>Now I want to open that file and get sage graphs from the list of canonical_label graph6_string</p>
<p>How can I do it?</p>
<p>Thank you!</p>
http://ask.sagemath.org/question/9606/how-to-get-a-graph-back-from-canonical_label-graph6_string/?answer=14346#post-id-14346You could define the following function.
def get_graphs_from_file(filename):
f = open( filename, 'r')
graph_list=[ Graph( l[:-1] ) for l in f ]
f.close()
return graph_list
And now, assuming the file `graphs.g6` contains a graph6 string per line, just run
sage: L=get_graphs_from_file( 'graphs.g6')
That should leave you with a list `L` of graphs.Tue, 04 Dec 2012 13:04:05 -0600http://ask.sagemath.org/question/9606/how-to-get-a-graph-back-from-canonical_label-graph6_string/?answer=14346#post-id-14346