python search txt 方式

https://www.delftstack.com/zh-tw/howto/python/python-find-string-in-file/#%e5%9c%a8-python-%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%aa%94%e6%a1%88-readlines-%e6%96%b9%e6%b3%95%e6%9f%a5%e8%a9%a2%e6%aa%94%e6%a1%88%e4%b8%ad%e7%9a%84%e5%ad%97%e4%b8%b2

https://github.com/dokelung/Python-QA/blob/master/questions/file/Python%E5%A6%82%E4%BD%95%E5%AF%A6%E7%8F%BE%E4%B8%A6%E8%A1%8C%E6%9F%A5%E6%89%BE%E9%97%9C%E9%8D%B5%E5%AD%97%E6%89%80%E5%9C%A8%E7%9A%84%E8%A1%8C.md

建議使用下列 不要用 readline()
with open(‘XXX’, ‘r’) as f:
for line in f:
if ‘txt’ in line:
# do something…

本篇發表於 python。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>