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.")



main()

Recommended Answers

All 3 Replies

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")

main()

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.