[Tutor] static methods & class methods
Steven D'Aprano
steve at pearwood.info
Fri Apr 20 18:28:54 CEST 2012
Surya K wrote:
> I have a class, and want to use a method of it in the class itself. How can
> I do it?
> I mean, say I defined foo() , bar() methods in a class myClass. So, how can
> we i use foo() in bar().
class C:
def foo(self):
print("foo")
def bar(self):
self.foo()
print("bar")
instance = C()
instance.bar()
> I tried to use @staticmethod, @classmethod, but I
> am getting some errors.. sometimes saying "unbound " and sometimes "given
> more than 1 parameters".. can any one tell me how to do this...
Do you expect us to guess what you do? Please show the SMALLEST example and
the actual error:
http://homepage1.nifty.com/algafield/sscce.html
> I java it really works well.
It works really well in Python too.
--
Steven
More information about the Tutor
mailing list