Search notes:

Python: __init_subclass__

__init_subclass__ is called when a subclass (not an instance) of a class is created.
class BASE():

      def __init__(self, ident):
          print(f'An instance of BASE is being initialized, ident = {ident}')
          self.ident = ident

      def __init_subclass__(cls, *a, **kw):
          print('A subclass of BASE is being created')

print('Going to create DERIV:')

class DERIV(BASE):

      def __init__(self, ident):
          print(f'An instance of DERIV is being initialized, ident={ident}')
          BASE.__init__(self, ident)

print('Finished with creation of DERIV')

base_1  = BASE(1)
deriv_2 = DERIV(2)
deriv_3 = DERIV(3)
Github repository about-Python, path: /dunders/__init_subclass__/demo.py

See also

__new__
Other dunders

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206517, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/dunders/__init_subclass__/index(65): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78