[Python-ideas] Anonymous namedtuples

Chris Angelico rosuav at gmail.com
Tue Apr 19 23:00:29 EDT 2016

On Wed, Apr 20, 2016 at 12:48 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Attributes and keys represent different concepts. Attributes represent
> an integral part of the object:
> dog.tail
> me.head
> car.engine
> book.cover
> while keys represent arbitrary (or nearly so) data associated with some
> data collection:
> books['The Lord Of The Rings']
> kings['Henry VIII']
> prisoner[239410]
> colours['AliceBlue']
> They don't just use different syntaxes, they have different purposes,
> and while it is tempting to (mis)use the shorter attribute syntax for
> key lookups:
> colours.AliceBlue
> it is risky to conflate the two.

Enumerations blur the line. You could define 'colours' thus:

class colours(enum.IntEnum):
    AliceBlue = 0xf0f8ff

Is "AliceBlue" a fundamental attribute of the "colours" object, or is
it a piece of data associated with the collection of colours? Or, like
Danny Kaye, perchance a brilliant combination of both?


More information about the Python-ideas mailing list