Python functools.namedtuple
Asked Answered
H

1

6

I am aware of the existence and purpose of collections.namedtuple, but I have noticed that, at least in IDLE (3.2.2), this factory function is also in functools:

>>> import functools
>>> functools.namedtuple
<function namedtuple at 0x024B41E0>

It also exists in collections as expected, and is the same function:

>>> import collections
>>> collections.namedtuple is functools.namedtuple
True

No docs I can find ever mention namedtuple being anywhere other than collections. So: is this standard, or just an IDLE weirdness? If it's just IDLE, is it a bug or a Why would namedtuple be in two places - and, indeed, in whose warped mind does it make sense in functools of all places?

Hintze answered 23/5, 2012 at 15:54 Comment(0)
B
10

In Python 3.2.2, functools.py contains the following import:

from collections import OrderedDict, namedtuple

It seems pretty clear that it's just a convenience import for the module's implementation, and is not intended to be part of its public interface.

Bluebill answered 23/5, 2012 at 15:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.