1
2 """Basic file output"""
3
5 """File for data output
6
7 The format of the file is: one data-set per line
8 Values are separated by tabs
9
10 The file is created the first time it is written"""
11
13 """name - name of the file"""
14 self.name=name
15 self.isOpen=False
16 self.handle=None
17 self.append=False
18
20 """A hook for outputting stuff at the beginning of the file"""
21 pass
22
24 """A hook for outputting stuff at the end of the file"""
25 pass
26
28 """A hook for outputting stuff at the end of each line"""
29 pass
30
32 """A hook for outputting stuff at the start of each line"""
33 pass
34
36 """A hook that gets called when the file is opened"""
37 pass
38
40 """A hook that gets called when the file is closed"""
41 pass
42
44 """get the file-handle. File is created and opened if it
45 wasn't opened before"""
46 if not self.isOpen:
47 mode="w"
48 if self.append:
49 mode="a"
50 self.handle=open(self.name,mode)
51 self.isOpen=True
52 if not self.append:
53 self.outputAtStart()
54 self.callAtOpen()
55
56 return self.handle
57
74
75 - def close(self,temporary=False):
76 """close the file
77 @param temporary: only close the file temporary (to be appended on later)"""
78
79 if self.handle!=None:
80 self.callAtClose()
81 if not temporary:
82 self.outputAtEnd()
83 else:
84 self.append=True
85 self.handle.close()
86 self.handle=None
87 self.isOpen=False
88