city = u'北京'
city_name = open(file_name, 'r').readline() # 文件中只有“北京”二字,且以UTF-8保存
若直接使用二者比较
if city == city_name:
pass
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
Right way
if city.decode('utf-8) == city_name:
pass