streamline input getting
This commit is contained in:
parent
70dd7657ec
commit
5e3d5d1156
21
aoc.py
21
aoc.py
@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import tools
|
import tools
|
||||||
from typing import List, Any, Type
|
from typing import List, Any, Type, Union
|
||||||
|
|
||||||
BASE_PATH = tools.get_script_dir()
|
BASE_PATH = tools.get_script_dir()
|
||||||
INPUTS_PATH = os.path.join(BASE_PATH, 'inputs')
|
INPUTS_PATH = os.path.join(BASE_PATH, 'inputs')
|
||||||
@ -59,6 +59,12 @@ class AOCDay:
|
|||||||
self.input = live_input
|
self.input = live_input
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def getInput(self) -> Union[str, List]:
|
||||||
|
if len(self.input) == 1:
|
||||||
|
return self.input[0]
|
||||||
|
else:
|
||||||
|
return self.input
|
||||||
|
|
||||||
def getInputListAsType(self, return_type: Type) -> List:
|
def getInputListAsType(self, return_type: Type) -> List:
|
||||||
"""
|
"""
|
||||||
get input as list casted to return_type, each line representing one list entry
|
get input as list casted to return_type, each line representing one list entry
|
||||||
@ -90,19 +96,6 @@ class AOCDay:
|
|||||||
|
|
||||||
return return_array
|
return return_array
|
||||||
|
|
||||||
def getInputAs2DArray(self, return_type: Type = None) -> List:
|
|
||||||
"""
|
|
||||||
get input for day x as 2d-array (a[line][pos])
|
|
||||||
"""
|
|
||||||
if return_type is None:
|
|
||||||
return self.input # strings already act like a list
|
|
||||||
else:
|
|
||||||
return_array = []
|
|
||||||
for line in self.input:
|
|
||||||
return_array.append([return_type(i) for i in line])
|
|
||||||
|
|
||||||
return return_array
|
|
||||||
|
|
||||||
def getInputAsArraySplit(self, split_char: str = ',', return_type: Type = None) -> List:
|
def getInputAsArraySplit(self, split_char: str = ',', return_type: Type = None) -> List:
|
||||||
"""
|
"""
|
||||||
get input for day x with the lines split by split_char
|
get input for day x with the lines split by split_char
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user