from graph_tool.all import Vertex, Graph
class MyVertex:
def __init__(self, g):
self.g = g
self.v = g.add_vertex()
self.halted = False
def vote_for_halt(self):
self.halted = True
def __getattr__(self, attr):
return getattr(self.v, attr)
if __name__ == "__main__":
g = Graph()
v1 = MyVertex(g)
v2 = MyVertex(g)
g.add_edge(v1, v2)
v1.vote_for_halt()
print v1.out_degree() # will print 1
print v1.halted # will print True
print v1.foo # will raise error: AttributeError: 'Vertex' object has no attribute 'foo'
Diff to Previous Revision
--- revision 1 2013-06-20 17:22:11
+++ revision 2 2013-07-18 10:02:59
@@ -10,10 +10,7 @@
self.halted = True
def __getattr__(self, attr):
- if attr not in self.__dict__:
- return getattr(self.v, attr)
- else:
- return self.__dict__.get(attr)()
+ return getattr(self.v, attr)
if __name__ == "__main__":
g = Graph()