Life is short, you need Python

splitlines

Python中的splitlines用来分割行。当传入的参数为True时,表示保留换行符 \n。通过下面的例子就很明白了:

mulLine = """Hello!!!
 Wellcome to Python's world!
    There are a lot of interesting things!
        Enjoy yourself. Thank you!
"""

print ''.join(mulLine.splitlines())
print '------------'
print ''.join(mulLine.splitlines(True))


输出结果:
Hello!!! Wellcome to Python's world!    There are a lot of interesting things!        Enjoy yourself. Thank you!
------------
Hello!!!
 Wellcome to Python's world!
    There are a lot of interesting things!
        Enjoy yourself. Thank you!

作者:CoderZhCoderZh的技术博客 - 博客园
出处:http://coderzh.cnblogs.com/

 

posted @ 2010-07-05 10:36  runfox545  阅读(550)  评论(0编辑  收藏  举报
白月黑羽 Python教程 白月黑羽Python