How to access args as a list?

Steve Howell showell30 at yahoo.com
Tue Apr 6 00:55:13 EDT 2010


On Apr 5, 11:49 am, kj <no.em... at please.post> wrote:
> In <4bb802f7$0$8827$c3e8... at news.astraweb.com> Steven D'Aprano <st... at REMOVE-THIS-cybersource.com.au> writes:
>
> >On Sat, 03 Apr 2010 22:58:43 +0000, kj wrote:
> >> 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.)
> >Does this help?
> >>>> def spam(a, b, c=3, d=4):
> >...     pass
> >...
> >>>> spam.__code__.co_varnames
> >('a', 'b', 'c', 'd')
>
> That's very handy.  Thanks!
>
> >The hardest part is having the function know its own name.
>
> Indeed.  Why Python does not provide this elmentary form of
> introspection as a built-in variable is extremely puzzling to me
> (even--no, *more so*--after reading PEP 3130).
>

The Rejection Notice in the PEP certainly not give very many details
for why the PEP was rejected.

The first question in the Open Issues could easily be answered "yes."




More information about the Python-list mailing list