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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -