[C++-SIG] Trouble getting a method called

Barry Scott barry at scottb.demon.co.uk
Mon May 22 21:34:18 CEST 2000


Here is a check list:

1. init_type() must be static.
2. all the init_type() functions must be called from your modules constructor
	[If not you will have no attributes]
3. from python do print dir(your_module) - check for all the module attributes
4. from python do print dir(your_object) - check for all the object attributes
5. from python do print your_object.__methods__ - check for all your methods

My guess is (2).

		BArry

> -----Original Message-----
> From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
> Behalf Of Steve Harris
> Sent: 22 May 2000 19:53
> To: c++-sig at python.org
> Subject: [C++-SIG] Trouble getting a method called
> 
> 
> I'm confused about the interaction between add_varargs_method() and
> getattr() in PythonExtension<>-derived types.
> 
> First, I tried defining a method, registering it with
> add_varargs_method() in my init_type() function, then calling the
> method from Python. My aim is to be as minimal as possible. Apparently
> my type isn't exposing the method properly:
> 
> > python
> Python 1.5.2 (#3, May 22 2000, 11:01:12)  [GCC 2.95.2 19991024 (release)] on sunos5
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> from seh_test import *  
> >>> p = some_pod( "a string" )
> Constructing some_pod( "a string" ): 0xd8c60
> >>> p.do_it()
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'some_pod' object has no attribute 'do_it'
> >>> ^D
> Destructing some_pod: 0xd8c6
> 
> 
> At that point, I realized that perhaps methods are just special
> functors returned from getattr(), so I tried to complete that
> implementation as follows:
> 
> ==================================================
> Py::Object py_bound_pod::do_it(const Py::Tuple& t)
> {
> 	// ...
> 	t.verify_length( 0 );
> 
> 	m_pod.do_it();
> 
> 	return Py::Nothing();
> }
> 
> 
> 
> // ....
> 
> Py::Object py_bound_pod::getattr(const char* pcsz)
> { return getattr_methods( pcsz ); }
> 
> 
> 
> void py_bound_pod::init_type()
> {
> 	Py::PythonType& pytype = behaviors();
> 	pytype.name( "some_pod" );
> 	pytype.doc( "A test POD type constructed from a string" );
> 
> 	pytype.supportRepr();
> 	pytype.supportGetattr();
> 
> 	add_varargs_method( "do_it", &py_bound_pod::do_it,
> 						"dump out the nested string" );
> }
> ==================================================
> 
> 
> With this setup, I get a different error:
> 
> >>> p.do_it()
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> RuntimeError: Extension object missing a required method.
> 
> 
> Can you see what I'm doing wrong, or do I need to post more of the
> source code?
> 
> -- 
> Steven E. Harris
> Primus Knowledge Solutions, Inc.
> http://www.primus.com
> 
> _______________________________________________
> C++-SIG maillist  -  C++-SIG at python.org
> http://www.python.org/mailman/listinfo/c++-sig
> 




More information about the Cplusplus-sig mailing list