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

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -