Hello SO, I have another question for you.
I have a python class with a list 'metainfo'. This list contains variable names that my class might contain. I wrote a __eq__
method that returns True if the both self
and other
have the same variables from metainfo
and those variables have the same value.
Here is my implementation:
def __eq__(self, other):
for attr in self.metainfo:
try:
ours = getattr(self, attr)
try:
theirs = getattr(other, attr)
if ours != theirs:
return False
except AttributeError:
return False
except AttributeError:
try:
theirs = getattr(other, attr)
return False
except AttributeError:
pass
return True
Does anyone have any suggestions as to how I can make this code easier on the eye? Be as ruthless as you please.