1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 @attention: This class is only used by Prosa.py which should be replaced
23 by L{Prosa2003}. It will only stay for a while until all transitions are made
24 to the new version of Prosa.
25 """
26
27 from UserList import *
28 import string
29 from copy import copy
30
32 - def __init__(self, lines = None, lists = None, format = None):
33 UserList.__init__(self)
34 if lines is not None:
35 for line in lines:
36 if not format:
37 words = string.split(line)
38 else:
39 words = []
40 for item in format:
41 words.append(string.strip(line[item[0]:item[1]]))
42 _l = []
43 for word in words:
44 try:
45 exec 'item = ' + word
46 except:
47 try:
48 exec 'item = "' + word + '"'
49 except:
50 item = ''
51 if type(item).__name__ in ['builtin_function_or_method',\
52 'module']:
53 item = word
54
55 _l.append(item)
56 self.data.append(_l)
57 else:
58 self.data = lists
59
60 - def joinColumns(self, left, right, fromRow = -1, toRow = -1, separator = ''):
61 if fromRow == -1: fromRow = 0
62 if toRow == -1: toRow = len(self.data)
63 if left == -1: left = 0
64 print fromRow, toRow
65 for row in range(fromRow, toRow):
66 dummy = copy(right)
67 if dummy == -1: dummy = len(self.data[row])
68 item = ''
69 for column in range(left, dummy):
70 newItem = self.data[row][column]
71
72
73 item = item + separator + str(newItem)
74 del self.data[row][left:dummy]
75 self.data[row].insert(left,item)
76
78 return Table(lists = self.data[i:j])
79
81 if type(index).__name__ == 'int':
82 return self.data[index]
83 else:
84 if type(index[0]).__name__ == 'slice':
85 lStart = index[0].start
86 lStop = index[0].stop
87 if lStart is None: lStart = 0
88 if lStop is None: lStop = len(self.data)
89 else:
90 lStart = index[0]
91 lStop = lStart + 1
92
93 if type(index[1]).__name__ == 'slice':
94 rStart = index[1].start
95 rStop = index[1].stop
96 if rStart is None: rStart = 0
97 if rStop is None: rStop = len(self.data)
98 else:
99 rStart = index[1]
100 rStop = rStart + 1
101
102 columns = self.columns(rStart,rStop)
103
104 return table(lists = columns[lStart:lStop])
105
107 return 'table('+UserList.__repr__(self)+')'
108
109 - def rows(self, rows):
110 try:
111 rows[0]
112 except:
113 rows = (rows,)
114
115 result = []
116
117 for row in rows:
118 result.append(self.data[row])
119
120 if len(rows) == 1:
121 return asTable(result[0])
122 else:
123 return asTable(result)
124
126 try:
127 columns[0]
128 except:
129 columns = (columns,)
130
131 result = []
132
133 if len(columns) == 1:
134 for row in self.data:
135 for column in columns:
136 result.append(row[column])
137 else:
138 for row in self.data:
139 col = []
140 for column in columns:
141 col.append(row[column])
142 result.append(col)
143
144 return asTable(result)
145
147 for row in rows:
148 del self.data[row]
149
151 for row in range(len( self.data)):
152 for column in columns:
153 del self.data[row][column]
154
156 f = open(name,'w')
157 map(lambda row, ff=f, ss=separator: ff.write(string.join(\
158 map(lambda item: str(item), row), ss) + '\n'), self.data)
159 f.close()
160
161
162 from Scientific.IO import TextFile
164
165 ll = TextFile.TextFile(fileName).readlines()
166 return Table(lines = ll, format = format)
167
169 return Table(lists = list)
170