[Python-ideas] Proposal to add new built-in struct (was: Add kwargs to built-in function object)

Brandon Mintern bmintern at gmail.com
Thu May 22 23:55:35 CEST 2008


On Thu, May 22, 2008 at 5:42 PM, Brandon Mintern <bmintern at gmail.com> wrote:
> This is a proposal to add a new built-in named struct:

One thing I forgot to mention... this is mainly intended to be used
where it makes sense to quickly build an anonymous object. It would be
considered bad practice to have more than one place in the code which
creates a struct having the same fields; in that case a NamedTuple (or
some equivalent) would be more appropriate.

In other words, this would be used in a similar situation to that of
lambda. You would not use lambda in several different places to define
the same function; as soon as you start to write it a second time,
you'd be much better to def the function and use it in both places. In
the same way, creating the same struct in two places is a good
indication that a NamedTuple or an actual class (possibly inheriting
from struct and using a non-kwargs constructor) is more appropriate.



More information about the Python-ideas mailing list