normally if not in function i just do print(resp) and get all the ouput on the terminal. When i do it in function below, im not able to get the same print output, I have set data() below to return the value but no output return and got error 'NameError: name 'request' is not defined. I think i miss somethg here...please advise me thanks. I really appreciate your advise and attention. Thank you
Re: No print output return value of rpc in a function
To use the return value of the function, please write it to a variable outside the function so you can print it outside of the function. Note that in general, you may only need to do one of the two i.e. either "print the result/response of the RPC within the function" or "print the result/response of the RPC outside the function" :).
Sharing an example similar to your function, one simple one and another one if you want to pass an argument (in paranthesis) to the function you define:
1) Simple function with no argument passed, includes a print within the function and one print outside the function.
from jnpr.junos import Device from lxml import etree
intf_info=data() print ("Outside the function info: \n") print (etree.tostring(intf_info,encoding='unicode'))