Users of namedtuple: do you use the _source attribute?

Thomas Nyberg tomuxiong at gmx.com
Wed Jul 19 02:37:01 EDT 2017


On 07/19/2017 05:12 AM, Steve D'Aprano wrote:
> On Wed, 19 Jul 2017 08:39 am, Gregory Ewing wrote:
> Um... well, people want to do all sorts of wild and wacky things... but why
> would you define a named tuple with *private* fields? Especially since that
> privateness isn't enforced when you access the items by position.

Maybe the user wants to match a naming convention that already exists? I
am doing this in code I'm writing at the moment. I'm not using
namedtuples, but if I were it would be nice if I could match the
conventions from earlier.

> In any case, the namedtuple API prohibits that, so it isn't an option.

Of course the API could have been different.

I'm not saying I think that private fields should be allowed, but there
certainly are valid use cases.





More information about the Python-list mailing list