aoc2020/aoclib/inputs.py
2020-12-01 11:27:01 +01:00

24 lines
654 B
Python

import os
BASE_PATH = os.path.dirname(os.path.dirname(__file__))
INPUTS_PATH = os.path.join(BASE_PATH, 'inputs')
def getInputLineAsArray(day, return_type=None, test=False):
"""
get input for day x as array, each line representing one array entry
when type is given, each entry will be converted to the specified type
"""
if test:
file = os.path.join(INPUTS_PATH, str(day) + "_test")
else:
file = os.path.join(INPUTS_PATH, str(day))
with open(file, "r") as f:
input_array = f.readlines()
if return_type:
return [return_type(i) for i in input_array]
else:
return input_array