文件过滤,显示一个文件中的特定行(这里去除行开始有“#”的行)

#-*- coding:utf-8 -

'''
Created on 2012-8-17

@author : shaolei
'''
#显示一个文件 的所有行,忽略以#号开头的行

#先打开一个文件以读的方式 
f = open('D:\pydev\shopnc_his_member.sql','r')
#print f.readline
countNum = 0
num = 0 
 
#利用一次循环算出有几行数据
for eachLine in f.readlines():
    #判断一行的开头字符是不是 #开始
    if  str(eachLine)[0] == '#':
        continue
    else:
        print "'the line without '#': ",eachLine
    countNum += 1   
    
print 
print 'the numbers of line is ',countNum


#关闭文件
f.close()









你可能感兴趣的:(读取文件,过滤)