v.0.7.5 SimpleCounter
This commit is contained in:
@@ -112,4 +112,4 @@ class Weather_Checker():
|
||||
except OSError as e:
|
||||
print(f'Error: connection closed - {e}')
|
||||
finally:
|
||||
print('finally done.')
|
||||
print('finally, check done.')
|
||||
@@ -4,4 +4,5 @@ from .time_utils import *
|
||||
from .font_utils import *
|
||||
from .math_utils import *
|
||||
from .url_encode import URLEncoder
|
||||
from .http_utils import http_message
|
||||
from .http_utils import http_message
|
||||
from .simple_counter import SimpleCounter
|
||||
39
app/utils/simple_counter.py
Normal file
39
app/utils/simple_counter.py
Normal file
@@ -0,0 +1,39 @@
|
||||
class SimpleCounter:
|
||||
_value: int
|
||||
|
||||
def __init__(self):
|
||||
self._value = 0
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._value = value
|
||||
|
||||
# Arithmetic operators
|
||||
def __add__(self, other):
|
||||
return self._value + other
|
||||
|
||||
def __sub__(self, other):
|
||||
return self._value - other
|
||||
|
||||
# In-place operators
|
||||
def __iadd__(self, other):
|
||||
self._value += other
|
||||
return self
|
||||
|
||||
def __isub__(self, other):
|
||||
self._value -= other
|
||||
return self
|
||||
|
||||
# Conversion and representation
|
||||
def __int__(self):
|
||||
return self._value
|
||||
|
||||
def __str__(self):
|
||||
return str(self._value)
|
||||
|
||||
def __repr__(self):
|
||||
return f"SimpleCounter(value={self._value})"
|
||||
Reference in New Issue
Block a user