Add a Class with a property decorator.
David Blume

David Blume commited on 2020-12-30 12:43:16
Showing 1 changed files, with 19 additions and 0 deletions.

... ...
@@ -32,6 +32,23 @@ def set_v_print(verbose: bool):
32 32
     v_print = print if verbose else lambda *a, **k: None
33 33
 
34 34
 
35
+class Coffee:
36
+
37
+    def __init__(self, price: float):
38
+        self._price = price
39
+
40
+    @property
41
+    def price(self):
42
+        return self._price
43
+
44
+    @price.setter
45
+    def price(self, new_price: float):
46
+        if new_price > 0 and isinstance(new_price, float):
47
+            self._price = new_price
48
+        else:
49
+            raise ValueError("price must be a non-negative float.")
50
+
51
+
35 52
 @timeit
36 53
 def main(debug: bool):
37 54
     start_time = time.time()
... ...
@@ -40,6 +57,8 @@ def main(debug: bool):
40 57
     counter.counter.run()
41 58
     v_print("Running sitesize...")
42 59
     sitesize.sitesize.run()
60
+    cuppa = Coffee(5.00)
61
+    cuppa.price = cuppa.price - 1.00
43 62
     print(f'{sys.argv[0]} is in {script_dir}.')
44 63
 
45 64
 
46 65