I recently visited a forum with python tricks and came across this:
>>> Points = type("Points", (object,), {'x' : None, 'y' : None})
>>> Player = Points()
>>> Player.x = 23
>>> Player.y = 54
>>> Player.x
23
>>> Player.y - Player.x
31
...
This syntax reminds me of the named tuples syntax:
>>> from collections import namedtuple
>>> Points = namedtuple("Points", ['x', 'y'])
>>> Player = Points(
x = 23,
y = 54
)
>>> Player.x
23
>>> Player.y - Player.x
21
...
And I can't understand how they differ except that named tuples can't be changed and have indexing. What advantages have named tuples and type function and what is better to use in our projects?