#-*-coding:utf-8-*-
import os
if __name__=='__main__':
codeline=0
expline=0
blankline=0
filename=raw_input('Please input the file name:')
fi=open(filename)
while fi.tell()!=os.path.getsize(filename):
temp=fi.readline()
if temp.startswith('#'):
expline+=1
elif temp=='/n':
blankline+=1
elif temp.startswith('"""'):
expline+=1
while True:
temp=fi.readline()
expline+=1
if temp.endswith('"""/n'):
break
else:
codeline+=1
else:
print 'the codeline is:'+str(codeline)
print 'the expline is:'+str(expline)
print 'the blank line is:'+str(blankline)
python中提供了很便捷的方法来判断两个文件的内容是否相同,只要两行代码:
>>>import filecmp
>>>filecmp.cmp(r'e:/1.txt',r'e:/2.txt')
如果两个文件相同,会输出True,否则会输出false。