Skip to content

Instantly share code, notes, and snippets.

@harukaeru
Created November 8, 2018 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harukaeru/97c009c5903d66ca92bf162a532482b1 to your computer and use it in GitHub Desktop.
Save harukaeru/97c009c5903d66ca92bf162a532482b1 to your computer and use it in GitHub Desktop.
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