Files
openide/python/testData/skeletons/FakeNamedTuple.py
2012-09-12 20:46:24 +04:00

19 lines
560 B
Python

from collections import namedtuple
Point = namedtuple('Point', 'x y')
p = Point(1, 2)
# Fields and unpacking
x, y = p
x, y, z = p
print(p.x, p.y, p.<warning descr="Unresolved attribute reference 'z' for class 'Point'">z</warning>)
print(Point.x, Point.y, Point.<warning descr="Unresolved attribute reference 'z' for class 'Point'">z</warning>)
# Tuple attributes
print(p.count(1), p.__class__, p.__add__((1, 2)))
# Named tuple attribute
print(Point.__slots__, Point._fields)
print(p.__module__, p.__slots__)
print(p._asdict(), p._fields, p._replace(x=42))