I found a Python script called transpose_file.py which can transpose space-delimited files. It looks like so:
import fileinput
m = []
for line in fileinput.input():
m.append(line.strip().split(" "))
for row in zip(*m):
print " ".join(row)
I want to make sure I understand what each line does, as I am very new to Python.
1) First, we import a module called fileinput which allows you to read files and parse through them? Not sure why using a simple with open(sys.argv[1],'r') as f etc would not work
2) Make an empty list called m
3) For each line in your input file, strip any space, tab or newline at the end of the line, and make space the delimiter (i.e. your input file is delimited)
4) For each row ... not sure what the rest means. What does zip(*m) mean? Once this is done, we print a space and we join the row? I just don't see how this results in a transposition.
Any explanation would be deeply appreciated.