Skip to content

Difficulty interpreting JSON result #21

Closed Answered by ScrappyCocco
NathanM0153 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @NathanM0153 and thanks for writing here
I think you are missing the fact that the search return an object of type HowLongToBeatEntry.py, looking at the test cases should help you understand how to use and read the returned object.

Here's the code you tried to write that correctly display the results accessing the struct

from howlongtobeatpy import HowLongToBeat

def findGame(name):
    results = HowLongToBeat().search(name, similarity_case_sensitive=False)
    if results is not None and len(results) > 0:
        best_element = max(results, key=lambda element: element.similarity)
        return best_element
    else:
        print("Not found")
        return

game = findGame("Portal")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NathanM0153
Comment options

Answer selected by NathanM0153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants