Gary E. Miller <[email protected]>: > Yo All! > > 2nd Python undocumented limitation: > > https://docs.python.org/2.7/library/collections.html?highlight=namedtuples#collections.namedtuple > > namedtuples makes no mention of a limitation on the number of elements in > a namedtuple. > > But: > > >>> a = collections.namedtuple('a', 'b', 'c', 'd', 'e') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: namedtuple() takes at most 4 arguments (5 given)
Your invocation syntax is wrong. You failed to notice that arg 2 is a list.
The correct way to do what you want is
a = collections.namedtuple("mytype", ['a', 'b', 'c', 'd', 'e'])
giving the tuple field names as a list of strings. The value of a will be
the new lightweight class object with the name "mytype".
The argument prototype on that page was trying to clue you in. Look
where it says:
collections.namedtuple(typename, field_names[, verbose=False][, rename=False])
Four formal args, two optional, and the second formal is a plural.
Good job spotting this feature, though. I only learned of it last week.
It's a real aid to readability.
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
signature.asc
Description: PGP signature
_______________________________________________ devel mailing list [email protected] http://lists.ntpsec.org/mailman/listinfo/devel
