Python functools.namedtuple

I know about the existence and purpose of collections.namedtuple , but I 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 

There are no documents I can find that ever mentioned namedtuple anywhere except collections. So: is this a standard, or just a weirdness? If it's just IDLE, is it a mistake, or why should namedtuple be in two places - and indeed, in whose perverted mind does this make sense in functools all places?

+6
source share
1 answer

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

 from collections import OrderedDict, namedtuple 

It seems pretty obvious that this is just a convenient import for the implementation of the module and is not intended to be part of its open interface.

+8
source

Source: https://habr.com/ru/post/916472/


All Articles