The following code is very helpful in the [python standard library:
= n n.name !== n
Yield at the beginning and end of the cycle graph is returned only once, as the starting point and ending point of the cycle graph, and n as the potential node of the graph. The next node is returned in each next call.
With this iterator, you can easily print the structure of the plot:
.join((n.name n self.all_nodes()))
->two->three->one
To implement a graph structure, you must use the weak references in python,
Let's take a look at the code of adding the next node to the standard graph structure:
%= other
After binding, add a reference to the next node in the attribute field.
c.: <Graph at 0xb7507e4c name=2>, : }
Therefore, even if you manually call a = None, B = None, c = None, the object will not be deleted.
Garbage:[<Graph at 0xb739856c name=one><Graph at 0xb739866c name=two><Graph at 0xb739868c name=three>: , : <Graph at 0xb739866c name=two>: , : <Graph at 0xb739868c name=three>: , : <Graph at 0xb739856c name=one>}]
Weak references refer to "referencing an object without increasing the pointer count of the referenced object"
You can use c = weekref. ref (k, func)
To specify the referenced object and the Action func after the object is deleted.
When calling, use c () to reference k
However, in the previous example, we need a "proxy object" to proxy the referenced object, so that the set_next function can be used as the variable other with the normal variable.
other self =
This avoids the use of other () to reference an other object ~