Python readline() is not reading a line with single space -


i reading text file using readline(). file contains below content space @ second line:

!  " # $ % &  

when print read values using-

print("'%s'\n" % iso5_char) 

it prints-

'!'  ''  '"'  '#'  '$'  '%'  '&' 

it seems readline() not reading 'space' @ second line.

i using python first time. have python-3.5 installed. wrong doing here? why space not read?

update: screenshot of file amreading:

enter image description here

based on comment original question, explicitly stripping out space expression:

iso5_char.rstrip() 

from documentation rstrip:

return copy of string trailing characters removed. if chars omitted or none, whitespace characters removed. if given , not none, chars must string; characters in string stripped end of string method called on.

in context, "whitespace" refers spaces, tabs, newlines, carriage returns, formfeeds, , vertical tabs.

if intent rstrip strip trailing newlines, can pass newline rstrip command:

iso5_char.rstrip(`\n') 

or, can chop off last character since it's safe assume it's newline:

iso5_char[:-1] 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -