Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a table from linear texts which contain columns and rows
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("filename", help="You set here files to parse.")
parser.add_argument(
"--transpose",
default=False, action='store_true',
help="Exchange column header and row header."
)
args = parser.parse_args()
lines = open(args.filename).readlines()
removed_lb_lines = [line.replace('\n', '') for line in lines]
x = []
y = []
is_switched = False
for line in removed_lb_lines:
if line == '---':
is_switched = True
continue
if args.transpose ^ is_switched:
y.append(line)
else:
x.append(line)
out = ''
out += '\t' + '\t'.join(x) + '\n'
for y_el in y:
out += y_el + '\n'
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment