[Tutor] Using string.strip()
Tue, 07 Aug 2001 23:30:56 -0700
OK, I'm having another one of my dumb moments...
As I read the docs for the strip() function for strings, it removes all
leading and trailing characters that are defined in the
string.whitespace constant, correct? And I even looked in there and SAW
the '\n' character listed as a whitespace element.
Now, why isn't this working?
I have a file that contains something like this:
no, cs student
I read it in as a string, let's call it messagebody
Then I do this:
responses = messagebody.split(';;')
Now, that will leave leading and trailing '\n' characters on the items
in the responses list, so I try this:
for item in responses:
item = item.strip()
But when I run it and print out the results, I still have leading and
trailing '\n' characters on the individual list elements, as though the
strip() function had no effect.
I've tried a few other things, too, but none of them seem to be working,
I thought that this was the whole purpose of the string.strip() command?