stripping spaces in front of line
Jorge Godoy
godoy at ieee.org
Fri Mar 3 23:19:38 EST 2006
eight02645999 at yahoo.com writes:
> 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
jupiter:~ $ pydoc string.strip
Help on function strip in string:
string.strip = strip(s, chars=None)
strip(s [,chars]) -> string
Return a copy of the string s with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping.
--
Jorge Godoy <godoy at ieee.org>
"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
More information about the Python-list
mailing list