|
This template function merely returns a triple of
'tuple_attributes':
>>> ChartEdgeTemplate()
('end','start','mother_cat')
Executing the following then creates a class called ChartEdge with
those 3 attributes:
>>> ChartEdge = supertuple.superTuplePlus('ChartEdge',ChartEdgeTemplate())
The ChartEdge class that ChartEdgeTemplate spawns is documented
here.
ChartEdges are tuples of end, start, and mother_cat, with gettable
attributes with those names provided for each instance.
Now we create an instance of the new class:
>>> e1 = ChartEdge(end= 1,start=0,mother_cat='s')
>>> e1
ChartEdge(1, 0, 's')
>>> e1.mother_cat
's'
This new class is a subclass of tuple and its instances really are
tuple instances supporting all the usual tuple methods:
>>> e1[2]
's'
They just have some extras, like the keyword access illustrated above
and a keyword display method:
>>> e1.display()
end: 1
start: 0
mother_cat: s
To test if e2 and e1 are equivalent: e1 == e2 (same as tuples) To test
if an edge equivalent to e1 occurs in list L:
e1 in L (same as tuples)
To find the index of an edge equivalent to e1 in list L:
L.index(e1) (same as tuples)
Note: Raises ValueError if L contains no such edge.
|