Python 3 Deep Dive Part 4 Oop High Quality Better

You now understand:

c = Concrete() c.process()

def constructor(self, val): self.val = val MyClass = type('MyClass', (object,), '__init__': constructor, 'x': 42) obj = MyClass(100) print(obj.val, obj.x) # 100 42 python 3 deep dive part 4 oop high quality

s1 = Singleton() s2 = Singleton() print(s1 is s2) # True You now understand: c = Concrete() c

Rarely. This is "High Quality" advice: Don't use metaclasses if a class decorator or __init_subclass__ will do. 'x': 42) obj = MyClass(100) print(obj.val

Подписка на новости блога: