So I want to compare two strings, sometimes one of them will be of type "unicode" and sometimes one of them will be of type "str".
This is what I've currently got:
def poll_change(self):
''' Returns a tuple (has_changed, new_element_str) '''
new_element = self.find_element()
old_element = self.read_element_str()
# TODO: handle compare correctly
if type(new_element) is not type(old_element):
changed = False
else:
changed = new_element != old_element
return changed, new_element
what would be the best solution for this?
Right now I am just returning False
if the types of the strings are unequal, but I would like to compare them anyways.
I would get an error if I would compare unicode with str for example.
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/difflib.py:433: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
a[besti-1] == b[bestj-1]
I am using Python 2.7