Python __init__ Vs __new__ Method - With Examples

This page summarizes the projects mentioned and recommended in the original post on /r/Python

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • CPython

    The Python programming language

  • It can be useful in some uncommon use cases to make some, let's say, "magic" classes. For example, the enum module in the stdlib makes use of __new__ to create enum classes.

  • copperfield-s-python-libraries

    collections of several modules

  • in the standard library I know of at least 3 use cases: fractions.Fraction (because it should be immutable they use new instead), pathlib.Path (as a dispatcher for your OS specific path class) and for metaclases shenanigans in abc.ABCMeta, there is also pure python version of it the module _py_abc.ABCMeta check those out in your local installation, I used that one as example to make my own metaclass one day that I was interested in such thing

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts