Skip to content

Instantly share code, notes, and snippets.

@ptigas
Created November 27, 2012 17:32
Show Gist options
  • Save ptigas/4155731 to your computer and use it in GitHub Desktop.
Save ptigas/4155731 to your computer and use it in GitHub Desktop.
unifying python api response
import json
class API :
ERROR = -1
OK = 0
class APIResponse(API) :
def __init__(self, code, data) :
self.code = code
self.data = data
def __str__(self) :
response = {}
response['code'] = self.code
response['data'] = str(self.data)
return json.dumps(response)
res = APIResponse(API.ERROR, "foo")
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment