hi... pyste noob here. i'm building some python interfaces for a library i've written and i'm trying to make the exposed python classes as "python-friendly" as possible (like nice iteration support). to do this, i'm trying to inject methods into my classes using add_method(). unfortunately, pyste is not finding the methods i'm requesting to be added. it seems to be related to the fact that the methods i'm having pyste add to the class aren't located in the same header file as the class. for example: [list.hpp] class list { ...; } [list_ext.hpp] iterator list_iterator(); [list.pyste] List = Class("list", "list.hpp") ListIterator = Function("list_iterator, "list_iterator.hpp") add_method(List, "list_iterator", "__iter__") or something very similar to that. it seems that the behavior of add_method only looks for methods defined in the file with the class - because this doesn't work with includes or added code either - quite frustrating. am i going about this completely wrong? any help would be appreciated. thanks in advance. andrew sutton asutton@cs.kent.edu
hi... pyste noob here.
i'm building some python interfaces for a library i've written and i'm
to make the exposed python classes as "python-friendly" as possible (like nice iteration support). to do this, i'm trying to inject methods into my classes using add_method(). unfortunately, pyste is not finding the methods i'm requesting to be added. it seems to be related to the fact that the methods i'm having pyste add to the class aren't located in the same
file as the class. for example:
[list.hpp] class list { ...; }
[list_ext.hpp] iterator list_iterator();
[list.pyste] List = Class("list", "list.hpp") ListIterator = Function("list_iterator, "list_iterator.hpp") add_method(List, "list_iterator", "__iter__")
or something very similar to that. it seems that the behavior of add_method only looks for methods defined in the file with the class - because this doesn't work with includes or added code either - quite frustrating.
am i going about this completely wrong? any help would be appreciated.
If I remember correctly, you need to add an 'Include' statement with a file that contains the function you are refering to in add_method(). If it fails, you can still fallback in 'class_code' to inject your method definition (you can find some example of this at: http://cvs.sourceforge.net/viewcvs.py/ogre/ogreaddons/pyogre/src/pyogre/ ). Baptiste. ----- Original Message ----- From: "Andrew Sutton" <asutton@cs.kent.edu> To: <c++-sig@python.org> Sent: Friday, August 20, 2004 4:50 AM Subject: [C++-sig] pyste question trying header thanks
in advance.
andrew sutton asutton@cs.kent.edu _______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig
On Monday 23 August 2004 02:54 am, Baptiste Lepilleur wrote:
If I remember correctly, you need to add an 'Include' statement with a file that contains the function you are refering to in add_method().
If it fails, you can still fallback in 'class_code' to inject your method definition (you can find some example of this at: http://cvs.sourceforge.net/viewcvs.py/ogre/ogreaddons/pyogre/src/pyogre/ ).
thanks for the response. unfortunately, i just realized that pyste doesn't quite generate code that's entirely right me (i can't derive some of my classes like that). guess it's back to straight boost.python. thanks again, andrew sutton asutton@cs.kent.edu
Hi Andrew, Andrew Sutton wrote:
On Monday 23 August 2004 02:54 am, Baptiste Lepilleur wrote:
If I remember correctly, you need to add an 'Include' statement with a file that contains the function you are refering to in add_method().
If it fails, you can still fallback in 'class_code' to inject your method definition (you can find some example of this at: http://cvs.sourceforge.net/viewcvs.py/ogre/ogreaddons/pyogre/src/pyogre/ ).
thanks for the response. unfortunately, i just realized that pyste doesn't quite generate code that's entirely right me (i can't derive some of my classes like that). guess it's back to straight boost.python.
I guess one alternative would be to create a subclass with the special methods you want, and export that instead of the original class. Regards, Nicodemus.
I guess one alternative would be to create a subclass with the special methods you want, and export that instead of the original class.
i don't think work for me. i'm dealing with a situation where objects can be instantiated from both python and the c++ library. what i ended up doing was creating simple C structs to wrap the classes i want and then build the python classes from C functions (no pyste). works nice. by the way, somebody should add some documentation warning users not to do this: Foo *f = new Foo; PyObject *ret = Py_None; if(...) { ret = object(f).ptr(); } return ret; it took me 2 weeks to figure out that the python object was being reclaimed before it was returned. that ends up in some pretty ugly bugs :) thanks for the feedback, andrew sutton asutton@cs.kent.edu
participants (3)
-
Andrew Sutton -
Baptiste Lepilleur -
Nicodemus