| Tor Norbye | 3a2425a | 2013-11-04 10:16:08 -0800 | [diff] [blame^] | 1 | from collections import namedtuple |
| 2 | |
| 3 | Point = namedtuple('Point', ['x', 'y'], verbose=True) |
| 4 | |
| 5 | print(Point.x, Point.y) |
| 6 | |
| 7 | p = Point(11, y=22) |
| 8 | print(p.x + p.y + p.<warning descr="Unresolved attribute reference 'z' for class 'Point'">z</warning>) |
| 9 | print(p.__add__) |
| 10 | print(p._asdict()) |
| 11 | print(Point._fields) |
| 12 | print(p._replace) |
| 13 | |
| 14 | if isinstance(p, Point): |
| 15 | p.x |
| 16 | |
| 17 | class C(namedtuple('C', 'x y')): |
| 18 | def f(self): |
| 19 | return self |
| 20 | |
| 21 | c = C() |
| 22 | print(c.x, c.y, c.<warning descr="Unresolved attribute reference 'z' for class 'C'">z</warning>, c.f()) |