Skip to content

Instantly share code, notes, and snippets.

@wwgist
Created June 11, 2014 14:09
Show Gist options
  • Save wwgist/afe1ae12349f540c83ff to your computer and use it in GitHub Desktop.
Save wwgist/afe1ae12349f540c83ff to your computer and use it in GitHub Desktop.
PYTHON: class creations
"""
Class object creation methods
"""
class Meta(type):
pass
# 1) via definition:
class A(object):
__metaclass__ = Meta
# 2) via constructor:
Meta('A', (object,), {})
# 3) via "__dict__" of "type"
cls = type.__dict__['__new__'](Meta, 'A', (object,), {})
type.__dict__['__init__'](cls, 'A', (object,), {})
# 4) via "super"
cls = super(Meta, Meta).__new__(Meta, 'A', (object,), {})
super(Meta, Meta).__init__(cls, 'A', (object,), {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment