![](/img/trans.png)
[英]In Python, searching a text file for multiple words and printing the corresponding lines
[英]Python: taking lines from a text file and searching words that start with "from" and outputting those lines
请试试这个:
with open('_my_file.txt', 'r') as _my_file:
# Iterates over the lines in file
for _ in _my_file.readlines():
# Ignore the case while searching
if _.casefold().startswith('from'):
print(_)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.