Simple question: how do I print output from .get() method
Rhodri James
rhodri at kynesim.co.uk
Wed May 30 08:00:24 EDT 2018
On 30/05/18 06:51, Chris Angelico wrote:
> On Wed, May 30, 2018 at 3:44 PM, MrMagoo2018 <Ronaldon2018 at gmail.com> wrote:
>> Hello folks, imagine I have the code below and I am getting the "error" message when attempting to print() the output of 'sw_report'.
>> Can you suggest which method I should use to retrieve this? Is that a dictionary maybe?
>>
>> from arista import arista
>> m = arista()
>> m.authenticate ("user","password")
>> sw_report = m.np.sw_report.get("swType="EOS",swMajorVersion="5.0")
>> print (sw_report)
>> <generator object arista._result_iterate at 0x7fdb30f0af10>
>
> That's not an error message. You asked Python to print it out, and it
> printed it out. As it happens, the display isn't particularly useful,
> but it's not an error.
>
> What you have is a *generator object*, which is something you can
> iterate over. I don't know about the arista library, so I don't know
> what you'll get from that, but at its simplest, you could convert that
> to a list:
>
> print(list(sw_report))
Be aware that if you do this, you will exhaust the generator and won't
be able to use it anywhere else.
>>> def foo():
... yield 1
... yield 2
... yield 3
...
>>> l = foo()
>>> print(l)
<generator object foo at 0x7f9010223150>
>>> print(list(l))
[1, 2, 3]
>>> print(list(l))
[]
--
Rhodri James *-* Kynesim Ltd
More information about the Python-list
mailing list