paranormal-or-skeptic/inout.py

22 lines
601 B
Python

import csv, lzma
# Reads input from directory and returns a list
def read(dir):
X = []
if 'xz' in dir:
with lzma.open(dir) as f:
for line in f:
text = line.decode('utf-8')
text = text.split('\t')
X.append(text)
else:
with open(dir) as f:
for line in f:
X.append(line.replace('\n', ''))
return X
# Takes the output (list) and writes it into directory
def write(output, dir):
with open(dir, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerows(output)