def pycmd_orderby(args, input, options): assert len(args) == 2 or len(args) == 3 table = CreateTableFromIterableRows(input) asc = True if len(args) == 3: args2 = args[2].lower() if args2 == 'desc': asc = False elif args2 != 'asc': raise Exception('args[2] must be desc or asc.') return table.orderby(args[1], asc, options.globals(), options.locals())
def pycmd_tocsv(args, input, options): table = CreateTableFromIterableRows(input) io = StringIO.StringIO() w = csv.writer(io) w.writerow(table.columns) for row in table: w.writerow(row.values()) return io.getvalue().split('\r\n')[:-1]
def pycmd_where(args, input, options): assert len(args) == 2 table = CreateTableFromIterableRows(input) return table.where(args[1], options.globals(), options.locals())