1 | from tabulate import tabulate |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | |||
4 | class Result(object): |
||
5 | |||
6 | def __init__(self): |
||
7 | self.records = [] |
||
8 | self.success = 0 |
||
9 | self.error = 0 |
||
10 | self.error_items = [] |
||
11 | |||
12 | def append(self, row): |
||
13 | id, status = row |
||
14 | |||
15 | if status: |
||
16 | self.success += 1 |
||
17 | else: |
||
18 | self.error += 1 |
||
19 | self.error_items.append(id) |
||
20 | |||
21 | def write(self): |
||
22 | if self.error > 0: |
||
23 | error_headers = ["File"] |
||
24 | error_result = [] |
||
25 | for id in self.error_items: |
||
26 | error_result.append([id]) |
||
27 | |||
28 | print("****** ERROR DETAILS ******") |
||
29 | print(tabulate(error_result, headers=error_headers)) |
||
30 | print("\n") |
||
31 | |||
32 | headers = ["Metric", "Count"] |
||
33 | result = [ |
||
34 | ["Success", self.success], |
||
0 ignored issues
–
show
|
|||
35 | ["Error", self.error], |
||
0 ignored issues
–
show
|
|||
36 | ] |
||
0 ignored issues
–
show
|
|||
37 | |||
38 | print("****** SUMMARY ******") |
||
39 | print(tabulate(result, headers=headers)) |
||
40 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.