I have grown to seriously dislike 'namedtuple'. It seems great, and it's so easy to use, but there's so few places it can be used without dragging in future backwards-compatibility baggage.<p>Let's say you have a light-weight object, like a "full name" which can be represented with a "forename" and an "surname". (Yes, there are many names which don't fit this category. This is a toy example.) So you write:<p><pre><code> from collections import namedtuple
FullName = namedtuple("FullName", "forename surname")
name = FullName("Edward", "Smith")
</code></pre>
So simple! So clean! No "self.forename = forename" or need to make your own __repr__.<p>Except you also inherit the tuple behavior, because this isn't really light-weight object but a ... let's call it a heavy-weight tuple.<p><pre><code> >>> name[0]
'Edward'
>>> name[1]
'Smith'
</code></pre>
This mean people may (okay, are likely) do things like:<p><pre><code> forename, surname = name
</code></pre>
or even<p><pre><code> for forename, surname in names:
...
</code></pre>
Even if that's not what you want in your API. If you care about backwards compatibility, then if you replace the namedtuple with its own class then you'll have to re-implement __getitem__, _replace, __len__, and count - methods which make no sense for a simple name class.<p>Or, if you decided to change the API, to make it be:<p><pre><code> FullName = namedtuple("FullName", "forename middlename surname suffix")
</code></pre>
then you'll again break code which used the full indexing API that you originally implicitly promised, simply by saying this is a namedtuple.<p>'namedtuple' has one good use - migration from a tuple object to a real object while allowing backwards compatability to the tuple API. For example, the old tuples once returned from os.stat() and time.gmtime().<p>It's also fine if it will only be used by code where you have full control over its use and can either prevent inappropriate API use like destructuring assignment, or can update all uses if you want to change the API. For example, a light-weight object used in a test-suite or internal helper function.<p>Otherwise, don't use it. Spend the extra few minutes so in the future you don't have to worry about backwards compatibility issues.