You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sledge/runtime/data/txt_split.py

21 lines
595 B

import sys
def split_columns(input_file):
columns = []
with open(input_file, 'r') as f:
for line in f:
parts = line.strip().split(',')
for i, part in enumerate(parts):
if len(columns) <= i:
columns.append([])
columns[i].append(part)
for i, column in enumerate(columns):
with open(f"{input_file[:-4]}_column_{i + 1}.txt", 'w') as outfile:
outfile.write("\n".join(column) + "\n")
if __name__ == "__main__":
for input_file in sys.argv[1:]:
split_columns(input_file)