[EMAIL PROTECTED] wrote: > hi > wish to ask a qns on strip > i wish to strip all spaces in front of a line (in text file) > > f = open("textfile","rU") > while (1): > line = f.readline().strip() > if line == '': > break > print line > f.close() > > in "textfile", i added some spaces in and then ran the code, it prints > out the lines without the spaces in front. I double checked "textfile" > and it does contains some lines with spaces in front. > Is it true that "readline().strip()" perform the removing of spaces in > front of a line as well? Is it documented anywhere? > I am using Windows environment. thanks >
You have observed the expected behavior. If you only want the trailing spaces stripped, try "rstrip". If you only want the leading spaces stripped, try "lstrip". If you want no space anywhere try this: line = "".join(f.readline().split()) If you want to normalize space, do this: line = " ".join(f.readline().split()) This should fulfill 90% of your space-transforming requirements. James -- http://mail.python.org/mailman/listinfo/python-list