Hi !
I have books.txt and it contain 20 books with author,the books.txt look like so..
Mark Lutz/learning python
James payane/Beginning Python
Noah gift/Python for Unix and Linux System Administration

If user search for book it just print book and author if user search for author print (“you cannot search for author here ,you should look for title books here!.”)

def main():
    search = input("which titel of book you are looking after? ")
    if search in open("books.txt").read():
        parts = search.split("/")
        for part in parts:
            print(parts, " Books found.")


Edited by tony75

6 Years
Discussion Span
Last Post by pyTony

You are not saving the books file which you read as one string at line 3 anywhere. Why are you splitting then input from user for title from '/'? Your example seems not allow '/' in title as it separates author from title.


Thanks Tony
If I change may question!

if user search for a book title or author and found was True it will show like this
Mark Lutz/learning python
if not tittle of book not found

def main():

    search = input("which titel of book you are looking for? ")
    file = open("books.txt")

    if search in open("books.txt").read():
        print(search, "found")


which titel of book you are looking for? learning python
learning python found

which titel of book you are looking for? Mark Lutz
Mark Lutz found

But I neaad the out put will be(book title and author)
Mark Lutz/learning python

Edited by tony75


But I am not sure user can be able to give exactly same format, maybe only Family name of author, then wouldn't it be actually more usefull to show what there is in the line matching instead of echoing back the search string? So you should iterate the file line by line for matches.

Maybe you could compare your code with my example data file code snipet? http://www.daniweb.com/software-development/python/code/293490/text-file-based-information-access-by-field-name-and-number

Edited by pyTony

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.