Re: [C++-SIG] Trouble getting a method called
"Barry Scott" <barry@scottb.demon.co.uk> writes:
Here is a check list:
1. init_type() must be static.
Check.
2. all the init_type() functions must be called from your modules constructor [If not you will have no attributes]
================================================== class seh_test_module : public Py::ExtensionModule<seh_test_module> { public: seh_test_module() : Py::ExtensionModule<seh_test_module>( "seh_test" ) { py_bound_pod::init_type(); add_varargs_method( "some_pod", &seh_test_module::new_py_bound_pod, "some_pod(str)" ); initialize( "seh_test module explores wrapping a C++ POD in a Python type" ); } ================================================== Check.
3. from python do print dir(your_module) - check for all the module attributes
print dir( seh_test ) ['__doc__', '__file__', '__name__','some_pod']
Okay.
4. from python do print dir(your_object) - check for all the object attributes
p = some_pod( "a string" ) Constructing some_pod( "a string" ): 0xd8c60 print dir( p ) []
Uh oh.
5. from python do print your_object.__methods__ - check for all your methods
print p.__methods__ Traceback (innermost last): File "<stdin>", line 1, in ? RuntimeError: Extension object missing a required method.
Uh oh. Anything else I can check? -- Steven E. Harris Primus Knowledge Solutions, Inc. http://www.primus.com
3. from python do print dir(your_module) - check for all the module attributes
print dir( seh_test ) ['__doc__', '__file__', '__name__','some_pod']
Okay.
The module is good.
4. from python do print dir(your_object) - check for all the object attributes
p = some_pod( "a string" ) Constructing some_pod( "a string" ): 0xd8c60 print dir( p ) []
Uh oh.
Here is the problem. The object p does not have any attributes. I suggest that you add cout << debug statements to confirm that the init_type() and getattr() are really called.
5. from python do print your_object.__methods__ - check for all your methods
print p.__methods__ Traceback (innermost last): File "<stdin>", line 1, in ? RuntimeError: Extension object missing a required method.
This is almost certainly the default getattr code running. Which only happens, in my experience, if init_type() is not called.
Uh oh.
Anything else I can check?
Make sure you have the latest sources from SourceForge. Make sure that the Demo example module works. BArry
participants (2)
-
Barry Scott -
Steve Harris