Python: Why does my function not display what's being returned in the interpreter? -
in python interactive interpreter:
i importing module contains class. these methods of class (some of them):
def do_api_call(self, params): return self.__apicall(params) def __apicall(self, params): return urllib2.urlopen(self.endpoint, params).read()
when import class , use method do_api_call(), doesn't output when finishes running.
def do_api_call(self, params): print(self.__apicall(params)) def __apicall(self, params): return urllib2.urlopen(self.endpoint, params).read()
i create instance of class , run method:
myapi = myapiclass() myapi.do_api_call(params={'param': 'value'})
when second version (note print function) however, outputs html of page being called.
why doesn't first version output anything? it's working (ie, it's getting page , not raising errors).
your first version returns value see output. second version prints value.
if you, consider storing return value of call first version variable , printing variable. should solve issue
Comments
Post a Comment