【问题标题】:How to search for a word in a txt file, then print the line that contains that word(Python)?如何在 txt 文件中搜索一个单词,然后打印包含该单词的行(Python)? 【发布时间】:2018-08-02 15:17:28 【问题描述】: 有谁知道我怎样才能做到这一点? 非常感谢您的帮助! 【问题讨论】: Search a text file and print related lines in Python?的可能重复 标签: python search 【解决方案1】: 非常基本的方法: with open("file.txt") as file: for line in file.readlines(): if "text" in line: print line 【讨论】: