python逐行读取文件脚本并去掉空行

python逐行读取文件脚本并去掉空行

逐行读取的方法很多,这里提供一种非常简单的方法:

#!/usr/bin/python
# -*- coding: utf-8 -*-

for line in open("awip.conf"):
    print line

该逐行读取有弊端,是有空行,下面的代码不会有空行

#!/usr/bin/python
# -*- coding: utf-8 -*-

def update_all_aw():
    for line in open("upmips.cfg"):
        a=line.strip()
        print(a)

update_all_aw()

其他的可以参考教程:
python逐行读取文件内容的三种方法
Python——文件读取