Question about extending the interperter

Fredrik Lundh fredrik at pythonware.com
Mon May 9 15:07:21 EDT 2005


"Eli" wrote:

> I've followed the Python docs about extending the Python interperter
> and created an extension library.
> I've added my functions like this:
>
> static PyMethodDef pmylib_methods[] = {
> {"foo", pmylib_foo, METH_VARARGS, "foo() doc string"},
> ...
> }
> static PyObject *pmylib_foo(PyObject *self, PyObject *args)
> {
> ...
> char *p;
> if (!PyArg_ParseTuple(args, "s", &p))
> ...
> }
>
> And that's works fine.
> The problem for me is that the pointer "p" in the last function points
> to the arguments:
> If a user caller foo("123") - p points to '123'.

foo("123") means "call the callable identifed by the expression 'foo' with
foo with the string '123'", so that's just what should happen.

> What I need is to point it to the whole string received - 'foo
> ("123")'.

received by whom?  if you call a function with an argument, the function
receives the argument.  the expression used to locate the callable (in this
case, the function name) is not part of the call.

> Is there a way I can do this?

no (at least not given how you've described your problem).

</F>






More information about the Python-list mailing list