1. 程式人生 > >python日記----2017.8.2

python日記----2017.8.2

一行 readlines pen 指定 查詢 補充 print not def

有待補充:

處理文件,用戶指定要查找的文件和內容
將文件中包含要查找內容的每一行都輸出到屏幕

def file(filename,find_l):
with open(filename,‘r‘,encoding=‘utf-8‘) as read_r:
lines = read_r.readlines()
for k,v in enumerate(lines):
# print(k)
if not v.find(find_l) == -1:
yield k+1, v
# else:
# yield ‘文件中沒有你想要查詢的值‘,enumerate(lines)

F = file(‘asd‘,‘一‘)
for f in F:
print(f)

python日記----2017.8.2