Better HN
topnewbestaskshowjobs
Log inSign up

JelleZijlstra

9 karma · joined Aug 30, 2017 (9y ago) · 2 submissions

Submissions

comment 9y ago · link · parent

If you're using Python 3.6, it's a lot easier now. You can do:

from typing import NamedTuple

class Point(NamedTuple): x: float y: float = 0.0

and then Point(1.0).y == 0.0.

comment 9y ago · link · parent

It's not actually; typing.NamedTuple is just a wrapper that calls the original collections.namedtuple. It does provide some additional features, like default values and methods.