On Thu, May 22, 2008 at 12:21 AM, Brandon Mintern email@example.com wrote:
I would like to propose to change the built-in function "object" to have the following syntax:
object(**kwargs) Return a new featureless object. object is a base for all new style classes. It has the methods that are common to all instances of new style classes.
If kwargs is given, the returned object's __dict__ will be kwargs (or something to that effect).
python 2.6 and 3.0 has something similar to this with collections.namedtuple:
The interface is a bit more verbose though:
Point = namedtuple('Point', 'x y') p = Point(11, y=22) # instantiate with positional or keyword arguments p + p # indexable like the plain tuple (11, 22)
x, y = p # unpack like a regular tuple x, y
p.x + p.y # fields also accessible by name
p # readable __repr__ with a name=value style
I like the syntax of using arguments to object though. Maybe there's a discussion behind namedtuple why they went that way instead of this one?