Ancestors

Toot

Written by Ned Batchelder on 2025-01-18 at 18:10

In #Python, @classmethod can used to create alternate constructors for making objects in other ways. Here's a simple example:

=> View attached media

=> More informations about this toot | More toots from nedbat@hachyderm.io

Descendants

Written by Anselm Schüler on 2025-01-18 at 18:26

@nedbat Importantly this is better than staticmethod because the cls parameter makes it work with subclassing

=> More informations about this toot | More toots from anselmschueler@ieji.de

Written by Keith Williams on 2025-01-18 at 20:59

@nedbat In my libraries I've used the convention for these alternative constructors to always start with 'mk'--typically with a description so yours would be "mk_random".

=> More informations about this toot | More toots from bonsai@hachyderm.io

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113850699714498142
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
297.413695 milliseconds
Gemini-to-HTML Time
0.394567 milliseconds

This content has been proxied by September (ba2dc).