From: Barry S. <ba...@ba...> - 2014-04-19 09:45:11
|
On 7 Apr 2014, at 12:42, Burak Kahraman <bur...@la...> wrote: > Hi Barry, > > I just started to write my own Python extensions and immediately switched to your library because of several positive posts on stackoverflow. > I really like it so far, but I have a very basic problem. I added my attributes by overriding getattro() as in the examples, but the thing is I want to see these attributes when using dir() on my object. So I have to declare these somehow. > With the regular functions I could create a static array of PyGetSetDef() (defining the attribute name and getter and setter functions) and assign it to tp_getset. > This doesn't work in my subclass of ExtensionModule, as I don't have access to the protected variable PythonType::tp_getset. > I also started a topic on stackoverflow without any luck yet :-\ > > Thanks for your great work and it would be nice to hear back from you. > The trick is that python asks for the value of __members__. In your code return a list of the names you want to see in dir(your_obj). This is a cut down version of what I did in pysvn code to support dir(). Py::Object pysvn_client::getattr( const char *_name ) { std::string name( _name ); if( name == "___members__" ) { Py::List members; members.append( "callback_get_login" ); members.append( "callback_notify" ); return members; } if( name == "callback_get_login" ) return m_context.m_pyfn_GetLogin; return getattr_default( _name ); } Barry > Best, > Burak > > -- > Burak Kahraman > Software Developer > > Laubwerk GmbH > August-Bebel-Str. 27 > 14482 Potsdam > Germany > > Phone +49 (0)30 / 609 86 48-01 > Fax +49 (0)30 / 609 86 48-09 > > www.laubwerk.com > facebook.com/laubwerk |