#!/usr/bin/python from math import sqrt, atan2, pi, sin, cos, floor from random import randint class Node: def __init__(self, name=None, parent=None): self._name = name self._parent = parent self._child = {} def newChild(self, name): _child[name] = Node(name=name, parent=self) def children(self): return self._child.values() def child_names(self): return self._child.keys() def child(self, name): return self._child[name] def parent(self): return self._parent def name(self): return self.name class Arc: def __init__(self, fromNode, toNode, name=None): self.fromNode = fromNode self.toNode = toNode def other(self, node): if node == self.fromNode: return self.toNode if node == self.toNode: return self.fromNode raise Exception, 'Node is not attached to this Arc' # should use a subclass of Exception? a = Node() b = Node() c = Node() arc = Arc(a, b) if arc.other(a) == b: print 'yes, working' if arc.other(b) == a: print 'yes, working'