【发布时间】:2017-06-15 13:10:26
【问题描述】:
我正在文本文件中搜索输入词。但是,我只打算在“START”一词之后搜索文件中的文本。 “START”之前的前二十位应该被忽略。我知道如何找到“START”,但不知道如何在遇到“START”后搜索文件的其余部分。我会很感激任何指导!
这是我目前所拥有的:
file = open("EnglishWords.txt", "r")
print("***** Anagram Finder *****")
word = input("Enter a word: ")
for line in file:
if "START" in line:
if word in line:
print("Yes, ", word, " is in the file.", sep="")
else:
print("Sorry, ", word, " is not in the file.", sep="")
file.close()
这是文本文件的示例:
The name of Princeton University or Princeton may not be
used in advertising or publicity pertaining to
distribution of the software and/or database. Title to
copyright in this software, database and any associated
documentation shall at all times remain with Princeton
University and LICENSEE agrees to preserve same.
START
clobber
transversalis
squinter
cunner
damson
extrovertive
absorptive
【问题讨论】:
-
如何迭代?逐词地?逐行?基本上你阅读直到你找到开始,然后继续阅读。你如何继续取决于你如何开始。即......到目前为止你有什么?
-
您能否edit your question 提供您的文本文件示例以及您想要在其中找到的内容。
-
同意@MartinEvans。文件格式/样式是什么?是一行一行的吗?还是段落样式?这将改变扫描方法。
-
我已经编辑包括我迄今为止的尝试...
-
this 可能重复?
标签: python python-3.x file