aboutsummaryrefslogtreecommitdiff
path: root/utils.py
blob: 273620667072b053ae4e6d217c8d9a3187905fe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys
import logging


def read_file(filename):
    lines = []

    if filename.is_dir():
        logging.fatal(f'{filename} is a folder instead of a file!')
        sys.exit(1)
    elif not filename.is_file():
        filename.touch()
    with open(filename) as filehandler:
        for line in filehandler.readlines():
            lines.append(line.strip())

    return lines

def write_file(filename, data):
    with open(filename, 'a') as filehandler:
        filehandler.write(data+'\n')