Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python __init_subclass__

In [16]: class Foo:
    ...:     def __init_subclass__(cls):
    ...:         print('ok')
    ...:         print(cls.att)

In [17]: class SubFoo(Foo):
    ...:     att = 1
    ...:     pass
    ...:
ok
1

# So: __init_subclass__ runs everytime that Foo is subclassed.
# Also: the argument `cls` of __init_subclass__ is the subclass.
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
6+6 =