Exceptions, assigning a tuple

Emile van Sebille emile at fenx.com
Sat Nov 29 14:35:35 EST 2003


Georgy Pruss:
>
> Mel Wilson:
> |    The use of tuple unpacking that surprised me most is in
> | function arguments:
[snip]
>
> That's a trick! Is it used? Does anybody use assignments like this:
> (a,((b,(c,)),d,e)) = (1,((2,(3+4,)),5,6))
>

A quick scan of the 2.3 standard library shows that it is used, but
only nestred to one level:

  * bdb.py(144): def user_exception(self, frame, (exc_type, exc_value,
exc_traceback)):
  * binhex.py(181): def __init__(self, (name, finfo, dlen, rlen),
ofp):
  * cgitb.py(168): def text((etype, evalue, etb), context=5):
  * cgitb.py(82): def html((etype, evalue, etb), context=5):
  * formatter.py(233): def push_font(self, (size, i, b, tt)):
  * imputil.py(278): def _process_result(self, (ispkg, code, values),
fqname):
  * inspect.py(507): def tokeneater(self, type, token, (srow, scol),
(erow, ecol), line):
  * modulefinder.py(258): def load_module(self, fqname, fp, pathname,
(suffix, mode, type)):
  * pdb.py(134): def user_exception(self, frame, (exc_type, exc_value,
exc_traceback)):
  * pydoc.py(197): def __init__(self, filename, (exc, value, tb)):
  * threading.py(126): def _acquire_restore(self, (count, owner)):
  * tokenize.py(135): def printtoken(type, token, (srow, scol), (erow,
ecol), line): # for testing

--

Emile van Sebille
emile at fenx.com





More information about the Python-list mailing list