Printing a generator returns "<generator object _as_iterable at 0x7f0476373e10>", need to print its values

Irmen de Jong irmen.NOSPAM at xs4all.nl
Mon Dec 5 14:21:44 EST 2016


On 5-12-2016 19:39, vmahajan at centerpointmedia.com wrote:
> On Wednesday, November 16, 2016 at 3:25:39 PM UTC-5, Peter Otten wrote:
>> vmahajan at centerpointmedia.com wrote:
>>
>>> I am running Python2.7, wherein I am running the following price of code:
>>>
>>> y = m.predict(input_fn=lambda:input_fn(df_predict), as_iterable=True)
>>> print ('Predictions: {}'.format(str(y)))
>>>
>>> The output of the following is ""<generator object _as_iterable at
>>> 0x7f0476373e10>"
>>>
>>> However, the desired output must be in the format [1 0 0 1 1 0 0 1].
>>>
>>> Can someone help me print the output in this format
>>
>> You give no context, but my suggestion would be to try and omit the 
>>
>> as_iterable=True
>>
>> part...
> 
> 
> Can someone help me print a generator object?
> 

Have you tried Peter's suggestion?

If that didn't work (but what is that as_iterable argument for then?) just iterate over
the result and print each value as it comes out of the generator:

    print("Predictions:")
    for value in y:
        print(value)


Irmen




More information about the Python-list mailing list