[英]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.