Importing a File to python

Associate
Joined
1 Dec 2010
Posts
1,657
Location
North Wales
Hi all trying to do some uni work but really struggling on this hope someone can help me!

Using this http://www.bogotobogo.com/python/python_Dijkstras_Shortest_Path_Algorithm.php
to work out a shortest path

What i'm trying to do is rather than have the nodes and distances in the program is to have them in a text file and have it load them rather than the ones in the program.

Code:
 # Use Graph()
		g = Graph()
		#Define a new array
		data = []
		# Open the import.txt file and import it into the array removing black space and splitting at commas.
		with open('import.txt') as inputfile:
			for line in inputfile:
				data.append(line.strip().split(','))

Is what i have so far however for the life of me cannot fine how to then take this data in data[] and put it into the graph so it can be used for the algorithm. Any direction would be appreciated!
 
Back
Top Bottom