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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -