ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 04 Dec 2012 20:04:05 +0100How to get a graph back from canonical_label graph6_stringhttps://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 15:46:46 +0100https://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>
https://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 20:04:05 +0100https://ask.sagemath.org/question/9606/how-to-get-a-graph-back-from-canonical_label-graph6_string/?answer=14346#post-id-14346