On Tue July 29 2008 8:42:08 am Jesus Cea wrote: > Amaury Forgeot d'Arc wrote: > |> My doubt now is how do write a *clever* "getattr" routine without > |> "Py_FindMethod". > | > | Well, I'd write a "tp_getattro" member function, > | which would do its "clever" things before it falls back to > | PyObject_GenericGetAttr to get the usual behaviour. > > Now I'm confused about difference between "tp_getattro" and > "tp_getattr", and when to use them. > > I guess that "tp_methods" and "tp_members" are faster, but only usable > when the data is "static" and available, while "tp_getattr" and friends > are used when you need to execute some code in the lookup. But I read > somewhere that "tp_getattr" was deprecated :-? ...
There is also the "tp_getset" slot (right after the "tp_members" slot) which is exactly for "computed" attribute access. See: http://docs.python.org/dev/extending/newtypes.html#providing-finer-control-over-data-attributes for further information. -- Jeremy Kloth http://4suite.org/ _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com