$ cat test1.py
#!/usr/bin/env python3
import hashlib
import datetime
class Animal:
def __init__(self, name='John', height=180):
dt_now = datetime.datetime.now()
self._id = hashlib.md5(str(dt_now).encode()).hexdigest()
self._name = name
self._height = height
def __del__(self):
print(self._id, 'is destruted...')
@property
def id(self):
return self._id
@property
def name(self):
return self._name
@property
def height(self):
return self._height
@name.setter
def name(self, name):
self._name = name
@height.setter
def height(self, height):
self._height = height
def get(self):
return self._id, self._name, self._height
if __name__ == '__main__':
# just for testing
# dt_now = datetime.datetime.now()
# print(dt_now)
# hs = hashlib.md5(str(dt_now).encode()).hexdigest()
# print(hs)
a1 = Animal()
print(a1.id)
print(a1.name)
print(a1.height)
print(a1.get())
a2 = Animal(name='Paul', height=183)
print(a2.id)
print(a2.name)
print(a2.height)
print(a2.get())
a3 = Animal(name='George', height=105)
print(a3.id)
print(a3.name)
print(a3.height)
print(a3.get())
del a1, a2, a3