I know people might be sick of this thread by now, but I decided to post a solution to this problem that uses regular expressions.
#!/usr/bin/env python import string import re def my_strip(s): remove_leading = re.sub(r'^\s+','',s) remove_trailing = re.sub(r'\s+$','',remove_leading) new_s = remove_trailing return new_s test = raw_input("Enter a string with leading and trailing whitespace: ") #print test new_s = my_strip(test) print new_s _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor