summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraric <none@none>2007-02-14 03:50:04 +0000
committeraric <none@none>2007-02-14 03:50:04 +0000
commite228563e7b364470fb4cf7b3dcb75a9fd29d1770 (patch)
tree604afcfc2c2a0c8c41958c8b6d653c6c4774b524
parent3469148ee2323e6d465256221ebde871205d4a0e (diff)
downloadnetworkx-e228563e7b364470fb4cf7b3dcb75a9fd29d1770.tar.gz
Allow tuple to be passed to get_edge()
Remove duplicate get_edge() in xdigraph - the one inherited from xgraph can be used. --HG-- extra : convert_revision : svn%3A3ed01bd8-26fb-0310-9e4c-ca1a4053419f/networkx/trunk%40522
-rw-r--r--networkx/xdigraph.py18
-rw-r--r--networkx/xgraph.py10
2 files changed, 6 insertions, 22 deletions
diff --git a/networkx/xdigraph.py b/networkx/xdigraph.py
index ce464cc5..45168f5b 100644
--- a/networkx/xdigraph.py
+++ b/networkx/xdigraph.py
@@ -260,24 +260,6 @@ class XDiGraph(DiGraph):
return (self.pred.has_key(n1) and
self.pred[n1].has_key(n2))
-
- def get_edge(self, n1, n2):
- """Return the objects associated with each edge between n1 and n2.
-
- If multiedges=False, a single object is returned.
- If multiedges=True, a list of objects is returned.
- If no edge exists, raise an exception.
-
- """
- try:
- result = self.adj[n1][n2] # raises KeyError if edge not found
- except KeyError:
- raise NetworkXError, "no edge (%s,%s) in graph"%(n1,n2)
- if self.multiedges:
- return result[:] # return a copy so user can't mess up list
- return result
-
-
def delete_multiedge(self, n1, n2):
""" Delete all edges between nodes n1 and n2.
diff --git a/networkx/xgraph.py b/networkx/xgraph.py
index 9a73cc1a..a1b50225 100644
--- a/networkx/xgraph.py
+++ b/networkx/xgraph.py
@@ -251,18 +251,20 @@ class XGraph(Graph):
for (u,v,d) in self.edges_iter(n):
yield v
- def get_edge(self, n1, n2):
- """Return the objects associated with each edge between n1 and n2.
+ def get_edge(self, u, v):
+ """Return the objects associated with each edge between u and v.
If multiedges=False, a single object is returned.
If multiedges=True, a list of objects is returned.
If no edge exists, raise an exception.
"""
+ if v is None:
+ (u,v)=u
try:
- result = self.adj[n1][n2] # raises KeyError if edge not found
+ result = self.adj[u][v] # raises KeyError if edge not found
except KeyError:
- raise NetworkXError, "no edge (%s,%s) in graph"%(n1,n2)
+ raise NetworkXError, "no edge (%s,%s) in graph"%(u,v)
if self.multiedges:
return result[:] # return a copy so user can't mess up list
return result