Reputation: 701
when i try to use strip() in the following condition, the output is a little different.
for line in tagfile:
tag_name = line.strip("<>")
print tag_name
the output is
strike>
but if I use the following method
tag_name = "<strike>"
print tag_name.strip("<>")
the output is
strike
Anybody who can help this?
Upvotes: 1
Views: 788
Reputation: 98088
It is due to the newline at the end of the line, strip does not go beyond it since you are not specifying newline as a 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
Upvotes: 3