PyObject_CallMethod muere al salir del metodo.

Chema Cortés py en ch3m4.org
Lun Oct 20 17:47:37 CEST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

El Sábado, 18 de Octubre de 2003 18:17, Maurizio Panniello escribió:

> >¿por qué construyes una nueva tupla a partir de tpar? ¿no bastaría con
> > poner "O" como cadena de formato?
>
> No, no vale, lo descubrí en el manual, CallMethod siempre quiere una
> tupla, incluso si llamas a una
> función sin argumentos tienes que poner un formato "()" para que genere
> una tupla vacias:
> http://www.python.org/doc/current/ext/callingPython.html

Igual no lo he leido bien, pero es este enlace se habla de cómo "evaluar" una 
función python, para lo cual construye una tupla con los argumentos y luego 
hace un "eval" (al estilo "pytoniso"). Para métodos, la documentación del 
CallMethod pone:

"""
PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...) 
Return value: New reference. 
Call the method named m of object o with a variable number of C arguments. The 
C arguments are described by a Py_BuildValue() format string. The format may 
be NULL, indicating that no arguments are provided. Returns the result of the 
call on success, or NULL on failure. This is the equivalent of the Python 
expression "o.method(args)". 
"""

Por lo que dice, si el método no tiene argumentos basta con poner NULL en 
lugar de la cadena de formato.

No me he puesto a probar, y los ejemplos que he pillado utilizan más 
"PyObject_CallMethodObjArgs" para invocar los métodos. Si ya lo has 
solucionado, pues nada. Pero hubiera sido ilustrativo mirar si con 
"PyObject_CallMethodObjArgs" se te arreglaba el problema. Aquí sí que está 
claro que la llamada sería: 

lob=PyObject_CallMethod((PyObject*)self, "_FF", tpar, NULL);



- -- 
Chema Cortes (py en ch3m4.org)
  http://py.ch3m4.org
    PGPKEY: mailto:pgpkey en ch3m4.org?subject=__PGPKEY__

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQE/lAOZHLTQrABk8H0RAhBtAKCfw657FRsWETddUAeVuhCaTLhQegCeNcL6
yBR5kyEp3xgIefSKUg8Q7CY=
=Bulh
-----END PGP SIGNATURE-----




Más información sobre la lista de distribución Python-es