[英]Else statement to print once in python
有没有办法一次打印“无日期”?
我总是这样打印
no date
no date
24 - 8 - 1995
no date
no date
no date
no date
no date
03 - 12 - 2014
no date
....
我想要这样打印
24 - 08 - 1995
03 - 12 - 2014
no date
15 - 10 - 1995
no date
这是代码
import os
for dirname, dirnames, filenames in os.walk('D:/Workspace'):
for filename in filenames:
if filename.endswith('.c'):
for line in open(os.path.join(dirname, filename), "r").readlines():
if line.find('date') != -1:
print line
break
else:
print "no date"
谢谢你的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.