1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# -*- coding: UTF8 -*-
"""tests on collection class"""
class collection:
def __init__(self, name):
self._data = []
self._name = name
self._pic = ""
def add(self, x):
self._data.append(x)
def delete(self, n):
del self._data[n]
def show(self, top):
""" prints recursively all elements of this collection """
#only for test reasons
print("**********")
print "collection: ", self._name
print "elements:"
for el in self._data:
el.show(False)
print "---- end of ", self._name
if top:
print # print an empty line after the last element
class task:
def __init__(self, name):
self._name = name
def show(self, top):
print "task: ", self._name
root = collection("root")
c1 = collection("c1")
t1 = task("t1")
t2 = task("t2")
c1.add(t1)
c1.add(t2)
c3 = collection("c3")
c3.add(t2)
c3.add(t1)
c1.add(c3)
root.add(c1)
# created: [[t1, t2, [t2, t1]]]
root.show(True)
# Versuch in einer Schleife dynamisch auf ein mit Koordinaten spezifiertes Object zuzugreifen
co=[0,2] # Koordinaten
print "pick element ", co
el = root
for n in co:
el = el._data[n]
el.show(True) # gewähltes Element anzeigen
# funktioniert!
|