How to access args as a list?

kj no.email at please.post
Sat Apr 3 19:55:10 EDT 2010


In <hp8kc9$dg7$1 at reader1.panix.com> kj <no.email at please.post> writes:

>In <hp8h73$k17$1 at reader1.panix.com> kj <no.email at please.post> 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.

Thanks.




More information about the Python-list mailing list