Row to Column Transposition (转置) using python
import sys
in_file = open(sys.argv[1])
out_file = open(sys.argv[2], 'w')
lis = [x.split() for x in in_file]
for x in zip(*lis):
for y in x:
print >> out_file, y + '\t',
print >> out_file # add '\n' throuth 'print'
out_file.close()
in_file.close()
########
#!/usr/bin/python
import sys
USAGE = "usage: python transposition_v2.py inputfile outfile"
if len(sys.argv) !=3:
print USAGE
sys.exit()
with open(sys.argv[1], 'r') as infile:
lis = [x.split() for x in infile]
with open(sys.argv[2], 'w') as outfile:
for x in zip(*lis):
outfile.write("\t".join(x) + "\n")

浙公网安备 33010602011771号