class method vs static method

Bruno Desthuilliers onurb at xiludom.gro
Tue Nov 21 06:00:31 EST 2006


Chris Brat wrote:
> Hi,
> 
> I've done some reading up but I cant get my head around how/why class
> methods can be used as apposed to static methods.

a "static method" is actually not much more than a plain function
living in a class's namespace. classmethods, OTOH, have access to the
class object.

> Can anyone give an example of where they have used class methods?

The canonical use case is factory methods, but you'll typically find
other possible applications in frameworks.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list