stripping spaces in front of line
Steve Holden
steve at holdenweb.com
Sat Mar 4 03:30:05 EST 2006
eight02645999 at yahoo.com 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
>
If you are using Windows then navigate to Start | All Programs | Python
2.4 | Python Manuals. Click the "Index" tab and enter "strip".
You will see that there is a strip() function in module string, and that
strings have a .strip() method.
This is called "Reading the Documentation". Do it more. Your time is no
more valuable than that of those who help on this list. Please try to
respect it by answering questions as best you can *before* resorting to
the list.
That way you'll continue to be a welcome visitor.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com
More information about the Python-list
mailing list