Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

Advanced Python Topics

Metaclasses

class Meta(type):
    def __new__(cls, name, bases, dct):
        return super().__new__(cls, name, bases, dct)
class MyClass(metaclass=Meta):
    pass

Descriptors

class Desc:
    def __get__(self, obj, objtype=None):
        return 42
class C:
    x = Desc()

Monkey Patching

def hacked():
    return 'hacked!'
import math
math.sqrt = hacked
print(math.sqrt())

Memory Profiling

import sys, gc
print(sys.getsizeof([1,2,3]))
gc.collect()