asa
asa

Reputation: 71

Testing a python recipe

I want to run a python recipe I found, but I don't know how as it imports from another one! For example, I would like to test the code here. I have downloaded it and also downloaded this one as it uses it.

So how can I test the this code by passing the needed parameter as below?!

>>> G = {'s':{'u':10, 'x':5}, 'u':{'v':1, 'x':2}, 'v':{'y':4}, 'x':{'u':3, 'v':9, 'y':2}, 'y':{'s':7, 'v':6}}
>>> Dijkstra.Dijkstra(G,'s','v')

I have added the two files in one of the python paths, and imported both but still get error Could you please give me some advice on simple way to test this code?

Upvotes: 0

Views: 584

Answers (1)

nneonneo
nneonneo

Reputation: 179552

You really should put the files in your current directory if you are just testing, instead of putting them in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ as that path is reserved for the Python standard library.

It seems that the second recipe, the Priority Dictionary, needs to be put in a file called priodict.py since the Dijkstra code imports from priodict. So, you should have the following files in your current directory: Dijkstra.py, priodict.py. Then you can just start Python and do import Dijkstra, and it should work.

Also, don't modify the Dijkstra code to remove the import as you apparently did...

Upvotes: 1

Related Questions