python strip() in reading lines from a file -


when try use strip() in following condition, output little different.

for line in tagfile:     tag_name = line.strip("<>")     print tag_name 

the output strike>

but if use following method

 tag_name = "<strike>"  print tag_name.strip("<>") 

the output strike

anybody can this?

it due newline @ end of line, strip not go beyond since not specifying newline token. try this:

for line in tagfile:     tag_name = line.strip("<>\n")     print tag_name 

or use this:

for line in tagfile:     line = line.rstrip()     tag_name = line.strip("<>")     print tag_name 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -