Difficulty interpreting JSON result #21
-
Hello, I'm having trouble doing anything with the result of the .search() method. Below is my function using it: def findGame(name): edit: this doesn't seem to be indenting correctly in this interface, but it obviously is indented in code. And the output: findGame("Portal") What exactly does this do, if I can't just return it? I can't find any info on how to interpret this in the JSONResultParser file, it doesn't seem like I can call the parse_web_result method directly, and looking through the main file it seems like should automatically decode this. The only SO posts I can find about this are about user-created objects that can't be displayed naturally, but .search() should return a list from what I see, not a custom object that has no good way to be displayed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @NathanM0153 and thanks for writing here 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")
print(str(game.game_name))
print(str(game.game_web_link))
print(str(game.profile_platforms)) This code correctly prints this
Please let me know if you understood or if you need additional help |
Beta Was this translation helpful? Give feedback.
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