def print_stack(file=_sys.stdout, levels=100, offset=0, locals=0): # Prepare frames try: raise ValueError except ValueError: # Go back offset+1 frames... f = _sys.exc_info()[2].tb_frame for i in range(offset + 1): if f.f_back is not None: f = f.f_back # Extract frames frames = [] while f: frames.append(f) f = f.f_back frames.reverse() # Prepare stack stack = _traceback.extract_stack() # Make output file.write('Stack:\n') for (frame,(filename, lineno, name, line)) in \ Tools.tuples(frames,stack)[-levels:]: file.write(' File "%s", line %d, in %s\n' % (filename, lineno, name)) if line: file.write(' %s\n' % line.strip()) if locals: print_frame_locals(frame, file, indent=' |', title='')
def print_stack(file=_sys.stdout,levels=100,offset=0,locals=0): # Prepare frames try: raise ValueError except ValueError: # Go back offset+1 frames... f = _sys.exc_info()[2].tb_frame for i in range(offset + 1): if f.f_back is not None: f = f.f_back # Extract frames frames = [] while f: frames.append(f) f = f.f_back frames.reverse() # Prepare stack stack = _traceback.extract_stack() # Make output file.write('Stack:\n') for (frame,(filename, lineno, name, line)) in \ Tools.tuples(frames,stack)[-levels:]: file.write(' File "%s", line %d, in %s\n' % (filename,lineno,name)) if line: file.write(' %s\n' % line.strip()) if locals: print_frame_locals(frame,file,indent=' |',title='')
def objects(self, constructor): """ Builds a list of objects by calling the given constructor with keywords defined by mapping column names to values for each input line. .columns must have been set using .set_columns() or by processing a given CSV header. """ lines = self.lines keys = self.columns if keys is None: raise Error, 'no columns set' objs = [None] * len(lines) for i, line in Tools.irange(lines): kws = dict(Tools.tuples(keys, line)) objs[i] = apply(constructor, (), kws) return objs
def objects(self,constructor): """ Builds a list of objects by calling the given constructor with keywords defined by mapping column names to values for each input line. .columns must have been set using .set_columns() or by processing a given CSV header. """ lines = self.lines keys = self.columns if keys is None: raise Error,'no columns set' objs = [None] * len(lines) for i,line in Tools.irange(lines): kws = dict(Tools.tuples(keys, line)) objs[i] = apply(constructor,(),kws) return objs