Search notes:

Python: __new__

class META(type):

      def __new__(cls, name, bases, body):

          print(f'  __new__'                         )
          print(f'    cls.__name__  = {cls.__name__}') # META
          print(f'    name          = {name        }') # BASE

          for k, v in body.items():
              print('    item[{!r}] = {!r}'.format(k, v))

          x = super().__new__(cls, name, bases, body)

          return x


print('Going to define/create a class:')

class BASE(metaclass=META):

      def __init__(self):
          print('  __init__')
          print('    id(self) = {}'.format(id(self)))
          print('    id(self.class) = {}'.format(id(self.__class__)))

      def f1(self):
          print('BASE.f1')

      def f2(self):
          print('BASE.f2')

print('Finished with the creation of the class')

b1 = BASE()
b2 = BASE()
Github repository about-Python, path: /dunders/__new__/demo.py

See also

__init__ is called when an instance of a particular class is created.
__init_subclass__ is called when a subclass (not an instance) of a class is created.
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...', 1758206548, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/dunders/__new__/index(78): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78