Python帮助创建在文本文件中搜索的程序 [英] Python help with creating a program that searches within a text file

查看:77
本文介绍了Python帮助创建在文本文件中搜索的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我是一般的编程新手,但之前做过一些简单到温和的程序。我目前正在努力弄清楚的是我将如何创建一个程序,使我能够在书籍的文本文件中搜索作者定义的特定书籍,出版年份,论文题目或期刊或会议名称。如果用户没有输入所有信息,则输出书籍,输出错误信息,说明书籍不会退出或输出错误信息。我不是简单地要求别人为我编写完整的代码,而是给我一个指示,告诉我如何从这开始,解释我需要使用哪些功能,或者指向一个我可以访问的网站找到相关信息来帮助解决这个问题。

解决方案

如果它是一个简单的文本文件,那么你需要逐行读取它 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆