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
Post a Comment