I think that
collections.namedtuple is not Pythonic enough for some use cases.
Recently, I wrote code like this:
disciplines =  for row in csv.reader(open('...csv')): level = 0 while row[level] == '': level += 1 disciplines.append((level, row, row.split('; '))) for i, d in enumerate(disciplines): if i < len(disciplines)-1 and disciplines[i+1] > disciplines[i]: continue # this is disciplines' category — skip it _, discipline_name, compets = d ... for compet in compets: ...
It would be more readable to write
disciplines[i+1].level > disciplines[i].level instead of
disciplines[i+1] > disciplines[i].
This can be achieved by using named tuple:
disciplines.append(namedtuple('_', 'level, name, compets')(level, row, row.split('; ')))
[And also line
_, discipline_name, compets = d will become unnecessary (but
in compets: just need to be replaced with
in d.compets: respectively).]
But I think Python should allow a more concise and readable syntax:
disciplines.append((level = level, name = row, compets = row.split('; ')))
Or even this:
disciplines.append((level=, name=row, compets=row.split('; ')))
(According to this proposal.)
So I propose to permit construct tuple from keyword arguments, which will allow accessing tuple items by their name.