Below is my code and it works with python 2 and not with python 3, minor changes have been added to make syntax compaitable with python3. Please help with this. ANd i get the error as
TypeError: get() missing 1 required positional argument: 'self'
import collections
from types import MethodType
_ApiMethod = collections.namedtuple('_ApiMethod', ['name', 'path', 'http_method', 'query_params'])
API = [
_ApiMethod('print_hello', 'api/hello', "GET", ['limit']),
]
class HelloClient(object):
def __repr__(self):
return "HelloClient(%s)" % ', '.join('%s=%s' % (a, repr(getattr(self, a))) for a in ['url', 'headers'])
def get(self, path,query_params=None, headers=None, **kwargs):
return "I am Hello Get Method"
def _add_methods():
def _build_method(path, http_method, expected_query_params):
if http_method == "GET":
def _method(self, **kwargs):
query_params = kwargs.setdefault('query_params', {})
query_params.update({qp: kwargs[qp] for qp in expected_query_params if qp in kwargs})
return self.get(path=path, **kwargs)
return _method
for api_method in API:
setattr(HelloClient, api_method.name, MethodType(_build_method(api_method.path, api_method.http_method, api_method.query_params or []), HelloClient))
_add_methods()
and i would call this method as
client = HelloClient()
response = client.print_hello()