lagranges / people_also_ask

Python wrapper for google people-alos-ask
MIT License
99 stars 43 forks source link

generator object generate_answer at 0x1012143c0 #16

Closed jachkoune closed 6 months ago

jachkoune commented 1 year ago

Hi and thanks for all the good job,

i got the error :generator object generate_answer at 0x1012143c0 when i try to display the result of below code:

`import people_also_ask

print(people_also_ask.generate_answer("coffee")) `

charliemday commented 1 year ago

Hi 👋 It looks like generate_answer returns a Python Generator instead of a standard list (which you're probably expecting). I'm guessing the reason a Generator is used in this case is for the large amounts of data so they're not read into your computer memory immediately (which would slow everything down)

You can look into the generator by running something like:

import people_also_ask
import time

answers = people_also_ask.generate_answer("coffee")

for answer in answers:
    print(" ")
    print(answer)
    print(" ")
    time.sleep(1)

For learning a bit more about Generators and why they're used take a look at: https://realpython.com/introduction-to-python-generators/