Filling in a tuple from unknown size list
stefan_ml at behnel.de
Fri Nov 27 21:11:01 CET 2009
Mel, 27.11.2009 18:47:
> Steven D'Aprano wrote:
>> On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote:
>>> Here's my question: Given a list of onknown length, I'd like to be able
>>> to do the following:
>>> (a, b, c, d, e, f) = list
>>> If the list has fewer items than the tuple, I'd like the remaining tuple
>>> elements to be set to "None". If the list is longer, I'd like the excess
>>> elements to be ignored.
>> I'd call that a code-smell. If I saw that in code, I'd think long and
>> hard about why it was there and if I could eliminate the names a...f and
>> just work directly with the list.
> It's a common enough thing at the boundaries of your program, letting user
> input in through the gates, as it were. Deeper in, I agree; that stuff
> should have been dealt with at the gates.
But that may have a code smell on it, too. In most cases, when users
provide excessive arguments that the program would ignore, that's best
treated as an error.
More information about the Python-list