Having a class like this:
class Spam(object):
def __init__(self, name=''):
self.name = name
eggs = Spam('systempuntoout')
using dis, is it possible to see how an instance of a class and the respective hex Identity are created?
Having a class like this:
class Spam(object):
def __init__(self, name=''):
self.name = name
eggs = Spam('systempuntoout')
using dis, is it possible to see how an instance of a class and the respective hex Identity are created?
Yes, but it isn't obvious from the output, which is at the level of Python bytecode, e.g.:
>>> class Foo(object):
... def f(x): return x * x
...
>>> dis.dis(Foo)
Disassembly of f:
2 0 LOAD_FAST 0 (x)
3 LOAD_FAST 0 (x)
6 BINARY_MULTIPLY
7 RETURN_VALUE
It doesn't take much to figure out what Foo.f is doing from the above dump, but it quickly becomes unreadable to most people as the size of the code grows.