[Tutor] why "self" in methods?
alan.gauld at blueyonder.co.uk
Mon Apr 5 19:31:23 EDT 2004
> > >>>>class SomeClass(object):
> > > ... def sayHello(self):
> > > ... print "hi, I'm SomeClass"
> > > ... def noSelf():
> > > ... print "I'm selfless"
> The newish facilities staticmethod() and classmethod() are for
> a selfless method, and one that takes the class as the self:
Yes and very welcome they are too. But I always thought the selfless
method should be interpreted as a class method(ie static method)
without any extra work. And up till 2.2 it was accepted but not
Of course what you've just pointed out is that these new features mean
my suggestion of issuing an error is no longer an option since Python
can't tell if you will call staticmethod() later... So I guess that
answers my question of what you can do with selfless methods - you can
make them into class methods by calling staticmethod(). Just seems a
wee bit clumsy IMHO.
Thanks for the reminder,
More information about the Tutor