[Tutor] extracting a column from many files
Moos Heintzen
iwasroot at gmail.com
Tue Feb 24 00:46:07 CET 2009
Here's a simple repositioning code given that you already have the
fields extracted.
All files have to have equal dimensions.
file1 = [["1a1", "1b1", "1c1",], ["2a1", "2b1", "2c1"],]
file2 = [["1a2", "1b2", "1c2",], ["2a2", "2b2", "2c2"],]
files = [file1, file2]
out_lines = []
for column in range(len(files[0][0])):
for fileno in range(len(files)):
out_lines.append([])
for row in range(len(files[0])):
out_lines[-1].append(files[fileno][row][column])
# write out_lines to file "file%s" % column
print out_lines
out_lines = []
No offense, but your extracting code looks a bit inflexible. It has a
lot of magic numbers, and most of it is hardcoded.
More information about the Tutor
mailing list