python - why pycharm gives a wrong condition check? -
i have string read file, there cases readline() return blank line , need check that, please see screenshot below , appreciated if can explain me why gives wrong result:
as can see screenshot, line='\n', why expression's evaluation result false?
there sure alternative way check blank line, curiously wanting know why script not working.
thank you.
thanks.
your input file contains nasty characters, "zero width space" or "invisible separator". can output these if print (or evaluate) repr(line)
:
with open('data.txt', 'w') f: f.write(u"\n") f.write(u"\u200b\n") # 0 width space f.write(u"\u2063\n") # invisible separator f.write(u"\n") open('data.txt', 'r') f: line in f: print(repr(line))
if debug above, able replicate behaviour lines 2 , 3, not lines 1 , 4. note these characters not visible in fonts (they not take space!), , printing/displaying them (as hovering in debugger) not reveal there.
in "evaluate expression" dialog in pycharm, simple evaluate "repr(line)
" see what's in it.
Comments
Post a Comment