Use "named constructors" to create multiple ways to initialize objects class PaperSize: @classmethod def iso_a4(cls): return cls(210, 297) def __init__(self, width_mm, height_mm): self.width_mm = width_mm self.height_mm = height_mm Try it: gist.github.com/simecek/fbe0fa… Inspired by @austin_bingham (@sixty_north) ⚡talk at #EuroPython2024
2
1
12
3K
5
@python_tip @classmethod Side note - @X really need to consider adding code formatting option to the posts!
@python_tip @classmethod So, what benefits do we have here?