Reputation: 57188
I am importing a module that contains a class. These are the methods of that 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 I import the class and use the method do_api_call(), it doesn't output anything when it 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 an instance of the class and run the method:
myapi = MyAPIClass()
myapi.do_api_call(params={'param': 'value'})
When I do the second version (note the print function) however, it outputs the HTML of the page that is being called.
Why doesn't the first version output anything? It's working (ie, it's getting the page and not raising any errors).
Upvotes: 1
Views: 189
Reputation: 114035
Your first version only returns the value that you would like to see as the output. The second version actually prints this value.
If I were you, I would consider storing the return value of the call to the first version into a variable and printing that variable. That should solve your issue
Upvotes: 1