Class methods in Python/C?

Jp Calderone exarkun at divmod.com
Tue Nov 30 14:54:45 CET 2004


On Tue, 30 Nov 2004 22:39:15 +1000, Nick Coghlan <ncoghlan at email.com> wrote:
>Craig Ringer wrote:
> > Hi folks
> > 
> > I've been doing some looking around, but have been unable to find out
> > how to implement class methods on Python objects written in C. "Why are
> > you using C?" you ask?
> > 
> > Yeah, so do I. However, I need to provide bindings for an application
> > that Python is embedded into, and thanks to Qt the bindings are going to
> > be both simple and quite powerful. However, I need a way to do class
> > methods...
> > 
> > If anybody has any tips on this, It'd be much appreciated.
> 
> You probably want to look at staticmethod(). (classmethod() is slightly 
> different, and probably not what you want. In fact, classmethod() is practically 
> *never* what you want. Guido wrote it himself, and even he ended up not using it)

  Funny, I find the exact opposite to be the case... ;)  Static methods are glorified free functions, but class methods participate usefully in inheritence hierarchies - why would anyone want the former?

  Jp



More information about the Python-list mailing list