Advertisement
Fabio_LaF

Classe Attribute

Aug 17th, 2022 (edited)
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. # file name: attribute.py
  2.  
  3. import datetime
  4.  
  5. class Attribute:
  6.   def __init__(self, field_name, value):
  7.     self.__field_name = field_name
  8.     self.__value = value
  9.  
  10.   @property
  11.   def value(self):
  12.     value_type = type(self.__value)
  13.     if value_type == str or value_type == datetime.date:
  14.       return "\'" + str(self.__value) + "\'"
  15.     else:
  16.       return self.__value
  17.  
  18.   @property
  19.   def field_name(self):
  20.     return self.__field_name
  21.  
  22.   def __eq__(self, other):
  23.     return isinstance(other, Attribute) and self.__field_name == other.__field_name and self.__value == other.__value
  24.  
  25.   def __repr__(self):
  26.     return "[" + self.__field_name + ": " + str(self.__value) + "]"
  27.  
  28.   def __hash__(self):
  29.     return hash(repr(self))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement