- Timestamp:
- 30 Jun 2008, 14:35:08 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/trunk/src/waeup/catalog.py
r3521 r3525 1 from __future__ import with_statement2 1 import sys 3 2 import csv … … 41 40 def render(self): 42 41 t = [0] 43 with accum_time(t): 44 src = os.path.join(os.path.dirname(__file__), 'tests', 45 'results2.csv') 46 inputfile = file(src, "r") 47 num = 0 48 headers, rows = readFile(inputfile) 49 for i in rows: 50 s = Student(i) 51 self.context[str(num)] = s 52 num += 1 42 src = os.path.join(os.path.dirname(__file__), 'tests', 43 'results2.csv') 44 inputfile = file(src, "r") 45 num = 0 46 headers, rows = readFile(inputfile) 47 for i in rows: 48 s = Student(i) 49 self.context[str(num)] = s 50 num += 1 53 51 return "%s new Students added in %s" % (num, t[0]) 54 52 … … 62 60 return "\n".join(result) 63 61 64 import contextlib, time65 66 62 class ExportStudents(grok.View): 67 63 grok.context(University) … … 69 65 def render(self): 70 66 t = [0] 71 with accum_time(t): 72 result = [] 73 for s in self.context.values(): 74 result.append(s.getCsv()) 75 writeFile(result) 67 result = [] 68 for s in self.context.values(): 69 result.append(s.getCsv()) 70 writeFile(result) 76 71 return "yeah %s" % t[0] 77 72 … … 91 86 writer.writerows(data) 92 87 93 @contextlib.contextmanager94 def accum_time(L):95 """96 Add time used inside a with block to the value of L[0].97 """98 start = time.clock()99 try:100 yield101 finally:102 end = time.clock()103 L[0] += end - start
Note: See TracChangeset for help on using the changeset viewer.