Skip to content

Commit 0bc63e8

Browse files
author
Emlyn Price
authored
Merge pull request #166 from EJEP/add_print_capability
Add print capability to Timestep, Element, Day and Site
2 parents 1d16c07 + d090813 commit 0bc63e8

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

datapoint/Day.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,20 @@ def __init__(self, api_key=""):
44

55
self.date = None
66
self.timesteps = []
7+
8+
def __str__(self):
9+
day_str = ''
10+
11+
date_part = 'Date: ' + str(self.date) + '\n\n'
12+
day_str += date_part
13+
14+
day_str += 'Timesteps: \n\n'
15+
try:
16+
for timestep in self.timesteps:
17+
day_str += str(timestep)
18+
day_str += '\n'
19+
20+
except TypeError:
21+
day_str += 'No timesteps'
22+
23+
return day_str

datapoint/Element.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ def __init__(self, id=None, value=None, units=None):
77

88
# For elements which can also have a text value
99
self.text = None
10+
11+
def __str__(self):
12+
return str(self.value) + ' ' + str(self.units)

datapoint/Site.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ def __init__(self, api_key=""):
1010
self.nationalPark = None
1111
self.region = None
1212
self.unitaryAuthArea = None
13+
14+
def __str__(self):
15+
site_string = ''
16+
for attr, value in self.__dict__.items():
17+
to_append = attr + ': ' + str(value) + '\n'
18+
site_string += to_append
19+
20+
return site_string

datapoint/Timestep.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ def elements(self):
2929
elements = [el[1] for el in self.__dict__.items() if isinstance(el[1], Element)]
3030

3131
return elements
32+
33+
def __str__(self):
34+
timestep_string = ''
35+
for attr, value in self.__dict__.items():
36+
to_append = attr + ': ' + str(value) + '\n'
37+
timestep_string += to_append
38+
return timestep_string

0 commit comments

Comments
 (0)