Python class representation under the hood
- by decentralised
OK, here is a simple Python class:
class AddSomething(object):
__metaclass__ = MyMetaClass
x = 10
def __init__(self, a):
self.a = a
def add(self, a, b):
return a + b
We have specified a metaclass, and that means we could write something like this:
class MyMetaClass(type):
def __init__(cls, name, bases, cdict):
# do something with the class
Now, the cdict holds a representation of AddSomething:
AddSomething = type('AddSomething', (object,), {'x' : 10, '__init__': __init__, 'add': add})
So my question is simple, are all Python classes represented in this second format internally? If not, how are they represented?
EDIT - Python 2.7