Re: unparsed sequence args
Guido.van.Rossum@cwi.nl
Fri, 07 Apr 1995 10:44:35 +0200
> Hi, I was wondering if there's a way to passed unparsed arguments to
> sequence like methods. For instance, for sq_ass_slice methods,
> instead of
>
> static int something_ass_slice(self, ilow, ihigh, v)
> somethingobject *self;
> int ilow, ihigh;
> PyObject *v;
> { ...
> }
>
> I rather have
>
> static int set_something_with_unparsed_index(self, index, v)
> somethingobject *self;
> PyObject *index, *v;
> {...
> }
>
> and have this called from Python with a syntax like:
>
> >>> a.[1,2,3] or
> >>> a.{1,2,3} or
> >>> a.<1,2,3> or
>
> something like this where Python passes the arguments within the
> brackets to my methods for somethingobject.
>
> Is this where tp_call comes into play?
Not quite. Such notations as you propose would require a change to
the syntax of the language, which is currently hardcoded. What you
can do with tp_call is implement the *function call* notation:
>>> a(1,2,3)
Your C function assigned to tp_call will then be called as any
built-in function:
PyObject *callit(self, args)
PyObject *self;
PyObject *args;
{
...
}
--Guido van Rossum, CWI, Amsterdam <mailto:guido@cwi.nl>
<http://www.cwi.nl/~guido/>