How to access args as a list?

kj at
Sun Apr 4 01:55:10 CEST 2010

In <hp8kc9$dg7$1 at> kj < at> writes:

>In <hp8h73$k17$1 at> kj < at> writes:

>>Suppose I have a function with the following signature:

>>def spam(x, y, z):
>>    # etc.

>>Is there a way to refer, within the function, to all its arguments
>>as a single list?  (I.e. I'm looking for Python's equivalent of
>>Perl's @_ variable.)

>>I'm aware of locals(), but I want to preserve the order in which
>>the arguments appear in the signature.

>>My immediate aim is to set up a simple class that will allow me to
>>iterate over the arguments passed to the constructor (plus letS me
>                                                       ^^^^^^^^^^^^
>>refer to these individual arguments by their names using an
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>instance.attribute syntax, as usual).
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>The underlined portion explains why __init__(self, *args) fails to
>fit the bill.

The minute I hit "send" I realized that this is wrong.  Sorry.


More information about the Python-list mailing list