How to convert a list/tuple into an function argument list easily?

Peter Hansen peter at engcorp.com
Mon Dec 16 18:25:28 EST 2002


Pierre Rouleau wrote:
> 
> Thanks to all that pointed out that *aList extends the list into its
> elements.
> I had been using it inside functions but never realized it could be used
> by itself.  I should have known...

Actually, I don't think you can use it "by itself"... it is special syntax
that has meaning only in the argument list of a function call, although the
meanings sort of mirror each other depending on whether you are calling the
function, or in the function being called.


Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
Alternative ReadLine 1.4 -- Copyright 2001, Chris Gonnerman
>>> aList = ['this', 'is', 'a', 'list']
>>> *aList
  File "<stdin>", line 1
    *aList
    ^
SyntaxError: invalid syntax
>>>

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> aList = ['this', 'is', 'a', 'list']
>>> *aList
  File "<stdin>", line 1
    *aList
    ^
SyntaxError: invalid syntax
>>>

-Peter



More information about the Python-list mailing list