Skip to content

Instantly share code, notes, and snippets.

@kaka19ace
Created November 22, 2015 14:27
Show Gist options
  • Save kaka19ace/6b0fa0be926df5cbfbeb to your computer and use it in GitHub Desktop.
Save kaka19ace/6b0fa0be926df5cbfbeb to your computer and use it in GitHub Desktop.
import json
class StatusCodeField(int):
def __new__(cls, status_code, message):
obj = int.__new__(cls, status_code)
obj.message = message
return obj
class BaseStatusCode(object):
pass
class UserStatusCode(BaseStatusCode):
EMAIL_INVALID = StatusCodeField(12345, "Email Invalid")
PASSWORD_INVALID = StatusCodeField(12346, "Password Invalid")
print(UserStatusCode.EMAIL_INVALID)
print(UserStatusCode.EMAIL_INVALID.message)
response_data = {"status_code": UserStatusCode.EMAIL_INVALID, "message": UserStatusCode.EMAIL_INVALID.message}
response_data_json = json.dumps(response_data, indent=2)
print(response_data_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment