Modifying Python parms passed to C function?

Richard Harvey tririch at connect.net
Thu Aug 31 12:34:03 EDT 2000


Ugh, I was afraid you were going to say that! The reason I'm wanting to do
this is that I have a collection of functions that users can call through a
.DLL using C, or through Python using my extensions.  I would greatly prefer
if the interface and documentation would remain the same regardless of what
tool the caller is using. What bothers me most is that Python does allow me
to modify lists, tuples, or dictionaries using the SetItem functions, and I
can essentially "pass back" the modified value; why do the PyInt_, PyFloat_,
or PyStr_ classes not offer a "set" function from C?

Well, I guess if that is the best Python offers I'll probably only allow a
small subset of my API to be available through Python, because the work it
would take to code and document 500-600 functions with specific Python
versions seems too costly.

Rich

Cedric Adjih <adjih at crepuscule.com> wrote in message
news:8olvoc$emv$1 at ites.inria.fr...
>   Well, unless I didn't understand your problem, there is no way
> to do it in pure Python either:
>
> def myFunc(parm1, parm2):
>     parm1=...
>     parm2=...
>     ...
>     return 1
>
> Doesn't change parm1 and parm2 they are integer (immutable).
>
> So I think this is the key of your problem.
> Either you can pass some mutable object holding one arg for each
> arg (for instance a list), or, much cleaner, you simply return
> the parm1,parm2 in a tuple (along with 1). In Python
>
> def myFunc(parm1, parm2):
>    ...
>    return 1, parm1, parm2
>
> -- Cedric





More information about the Python-list mailing list