Python帮助创建在文本文件中搜索的程序 [英] Python help with creating a program that searches within a text file
问题描述
如果它是一个简单的文本文件,那么你需要逐行读取它 https://docs.python.org/3.3/distutils/apiref.html? highlight = text%20file%20read#module-distutils.text_file [ ^ ]。然后你必须阅读每一行并搜索该行中的特定字段,直到你得到一个匹配。
Hi there. I'm new to programming in general but have made some simple to moderate programs before. What I'm currently struggling to figure out is how I would create a program that would allow me to search for a specific book defined by the author, year of publication, paper title or name of journal or conference within a text file of books and output the book, output an error message saying the book doesn't exits or output an error message if the user doesn't input all the information. I'm not simply asking for someone to write the entire code for me, but rather give me an indication as to how I could start with this, explain what functions I would need to use, or to point me to a website where I could find relevant information to help with this.
If it is a simple text file, then you would need to read it line by line with https://docs.python.org/3.3/distutils/apiref.html?highlight=text%20file%20read#module-distutils.text_file[^]. Then you would have to read each line and search for the specific fields in that line until you get a match.
这篇关于Python帮助创建在文本文件中搜索的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!