#dataclasses

[ follow ]
fromMathspp
4 months ago

Recursive structural pattern matching

Structural pattern matching excels at... matching the structure of your objects! For the two examples in this article, we'll be using a number of dataclasses that you can use to build abstract Boolean expressions: from dataclasses import dataclass class Expr: pass @dataclass class And(Expr): exprs: list[Expr] @dataclass class Or(Expr): exprs: list[Expr] @dataclass class Not(Expr): expr: Expr @dataclass class Var(Expr): name: str
Python
#python
fromThepythoncodingstack
6 months ago
Python

I Don't Like Magic * Exploring The Class Attributes That Aren't Really Class Attributes * [Club]

Dataclass and NamedTuple shared class-block syntax can feel like hidden 'magic' compared to explicit class attributes and __init__ instance assignments.
fromInfoWorld
6 months ago
Python

How to use Python dataclasses

Dataclasses automatically generate common class boilerplate (constructors, representation, and comparisons) from declared fields, reducing repetitive code and errors.
Python
fromInfoWorld
6 months ago

Python vs. Mojo (and Java, Go, Rust, and .NET)

Mojo, alternative data-science languages, Python dataclasses, and a new PyTorch-related distributed-processing framework are current focal points for Python practitioners.
[ Load more ]