如何用python把文件中每行字符前面的空格去掉?

如何用python把文件中每行字符前面的空格去掉?

比如有如下文件:
This is the fist line
    this is second line and with some space in the front
hi! I'm the 3rd line!

变成:
This is the fist line
this is second line and with some space in the front
hi! I'm the 3rd line!



谢谢!


[Copy to clipboard] [ - ]
CODE:
>;>;>; f=open(r'd:\test.txt', 'r')
>;>;>; while 1:
...         line = f.readline()
...         if not line: break
...         print line.strip()
...        
This is the fist line
this is second line and with some space in the front
hi! I'm the 3rd line!

Yeah! Thanks a lot!

我原来还想着需要好多行语句才能解决,没想到利用一个字符串的方法就解决了!对于初学者来说,如果有一本中文版的参考手册,那该多好啊!
你仔细找一下,已经有很多python中文化的东西了。
这些东西还在于编程的经验,用得多了就熟了。因此需要对python的模块,内置的方法,类的方法要熟悉才行,需要自已多看。还有就是对于拿不准的或希望可以改进的地方拿出来讨论,然后再根据讨论结果进行有目的的学习在,比光在那里啃书要强得多。
>>> for line in open('urfile', 'r'):
...     print line.lstrip(),
...
This is the fist line
this is second line and with some space in the front
hi! I'm the 3rd line!
import re
r=open('file','r')
s=r.readlines()
r.close()
ss=''
for i in s:
ss+=re.sub('^\s*','',i)
print ss
这样行不行呀,我也刚学python
我写小一个小脚本,有空去看一看
http://yesorwong.appspot.com
>>> [line.lstrip() for line in open("c:/response.txt")]

这个帖子也被翻出来了啊。。。
今天学到一招。
应该可以用reduce()来解决。