# ValueError: need more than 1 value to unpack - python graph core

I was planning to try to use this code in order to do a critical path analysis. When running this code I got the following error but I have no idea what it means (because I don't now how the code works).

Traceback (most recent call last): File "/Users/PeterVanvoorden/Desktop/test.py", line 22, in G.add_edge('A','B',1) File "/Library/Python/2.7/site-packages/python_graph_core-1.8.2-py2.7.egg/pygraph/classes/digraph.py", line 161, in add_edge u, v = edge ValueError: need more than 1 value to unpack

# Copyright (c) 2007-2008 Pedro Matiello <pmatiello@gmail.com> # License: MIT (see COPYING file) import sys sys.path.append('..') import pygraph from pygraph.classes.digraph import digraph from pygraph.algorithms.critical import transitive_edges, critical_path #demo of the critical path algorithm and the transitivity detection algorithm G = digraph() G.add_node('A') G.add_node('B') G.add_node('C') G.add_node('D') G.add_node('E') G.add_node('F') G.add_edge('A','B',1) G.add_edge('A','C',2) G.add_edge('B','C',10) G.add_edge('B','D',2) G.add_edge('B','E',8) G.add_edge('C','D',7) G.add_edge('C','E',3) G.add_edge('E','D',1) G.add_edge('D','F',3) G.add_edge('E','F',1) #add this edge to add a cycle #G.add_edge('E','A',1) print transitive_edges(G) print critical_path(G)

I know it is kind of stupid just to copy code without understanding it but I thought I'd first try the example code in order to see if the package is working but apparently it's not working. Now I wonder if it's just because of a little mistake in the example code or if it's a more fundamental problem.

## Answers

I peeked at the source code for this and see that add_edge is trying to unpack the first positional argument as a 2-tuple.

If you change these lines:

G.add_edge('A','B',1) G.add_edge('A','C',2) ...

to:

G.add_edge(('A', 'B'), 1) # note the extra parens G.add_edge(('A', 'C'), 2) ...

it should work. However, I have not used pygraph before so this may still not produce the desired results.