Anonymus functions revisited

Claudio Grondi claudio.grondi at freenet.de
Tue Mar 22 10:59:02 EST 2005


>  for x,y,z in some_iterator:
>
> If some_iterator produces at some time
> a tuple with only two elements this
> will raise an exception no matter
> whether you assigned z already or not.

So if I now understand it right, the core
of the whole proposal is to find a way to
make unpacking of tuples work also in case
the tuples have not the appropriate
number of elements, right?

So to achieve the same effect I need
currently (not tested):

for x,y,z in [getMyTargetTupleFrom(currentTuple) for currentTuple in
tupleList]

where getMyTargetTupleFrom(currentTuple) is:

def getMyTargetTupleFrom(currentTuple):
  if len(currentTuple) >= 3:
    return (currentTuple[0], currentTuple[1], currentTuple[2])
  if len(currentTuple) == 2:
    return (currentTuple[0], currentTuple[1], 0)

right?

Is it really worth it?
Isn't it much easier to convert the list of tuples
explicit to appropriate format, first?

It seems, that my attitude to the proposal
is originated from bad experience with
default values.

  To get it tracked down to the point:

In my opinion default values are evil and it
is enough trouble that function defintions
allow them.
I have seen already postings
of confused newbies expecting the
default values beeing set during
function execution not during
definition and I have also faced
this problem starting on Python
myself .

Claudio





More information about the Python-list mailing list