python - Unicode Dash not detected by if statement -
using python 2.7.11
dashes utf-8 document i'm reading in being ignored if statements intended detect them. dash prints console '-' character, , when shown representation displays u'-'. character passed through ord() displays ordinal 45, same dash character.
segment = line[:section_widths[row_index]].strip() line = line[section_widths[row_index]+1:] if segment: print 'seg' if segment u'-' or segment '-': print 'dash detected' continue print "ord %d" % ord(segment[0])
do not use is
equality check. use ==
equality check.
>>> 'stringstringstringstringstring' == 'string' * 5 true >>> 'stringstringstringstringstring' 'string' * 5 false
is
should used identity check.
Comments
Post a Comment