blob: 70c3ac0b3848c36706e7f21555d3f7abc99dd7ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import os
from abc import ABC
from collections import Iterator
from typing import Generator, Any
class BaseAssignment(ABC):
def __init__(self, path):
self.path = path
def parse_item(self, item: str) -> Any:
return item
def read_input(self, example = False) -> Generator:
file = f'{self.path}/input.txt'
if example or not os.path.isfile(file):
file = f'{self.path}/example.txt'
with open(file, 'r') as input_file:
for line in input_file.readlines():
yield self.parse_item(line.strip())
def run(self, input: Iterator) -> Any:
raise NotImplementedError('Please implement run')
|