Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assuming the file graphs.g6 contains one graph6 string per line you could do the following.

def get_graphs_from_file():
    f = open( 'graphs.g6', 'r')

Assuming You could define the following function.

def get_graphs_from_file(filename):
    f = open( filename, 'r')
    graph_list=[]
    for l in f:
       graph_list.append( Graph(l[:-1] ) )
    f.close()
    return graph_list

And now, assuming the file graphs.g6 contains one a graph6 string per line you could do the following.line, just run

def get_graphs_from_file():
    f = open( 'graphs.g6', 'r')
sage: L=get_graphs_from_file( 'graphs.g6')

That should leave you with a list L of graphs.

You could define the following function.

def get_graphs_from_file(filename):
    f = open( filename, 'r')
    graph_list=[]
    graph_list=[ Graph( l[:-1] ) for l in f:
       graph_list.append( Graph(l[:-1] ) )
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.