*-unpacking

Lulu of the Lotus-Eaters mertz at gnosis.cx
Fri Oct 3 00:56:25 EDT 2003


|Alex Martelli wrote:
|> How sweet it would be to be able to unpack by coding:
|>     head, *tail = alist

"Greg Ewing (using news.cis.dfn.de)" <g2h5dqi002 at sneakemail.com> wrote previously:
|    command arg arg ...
|   command, *args = cmdstring.split()
|and get the command as a string and a list of 0 or more argument strings.

I think I've written on this list before that I would like this
too--Ruby does this, IIRC.  If anyone writes a PEP, you have my +1 in
advance.

For Greg's particular case, one approach that doesn't look too bad is:

    command = args.pop(0)
    # ... do stuff ...
    try:
        more = args.pop(0)
    except IndexError:
        # no more

For a really long list, it would be faster to do an 'args.reverse()' up
front, and '.pop()' off the end (Greg and Alex know all this, of course).

Yours, Lulu...

--
 mertz@  _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_    n o
gnosis  _/_/             Postmodern Enterprises            \_\_
.cx    _/_/                                                 \_\_  d o
      _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e






More information about the Python-list mailing list