code: def reorder(args):
      
      import csv
  
      p = OptionParser(reorder.__doc__)
      p.set_sep()
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      tabfile, order = args
      sep = opts.sep
      order = [int(x) - 1 for x in order.split(",")]
      reader = csv.reader(must_open(tabfile), delimiter=sep)
      writer = csv.writer(sys.stdout, delimiter=sep)
      for row in reader:
          newrow = [row[x] for x in order]
          writer.writerow(newrow)
docs: %prog reorder tabfile 1,2,4,3 > newtabfile
  
      Reorder columns in tab-delimited files. The above syntax will print out a
      new file with col-1,2,4,3 from the old file.