[Tutor] static methods & class methods

Joel Goldstick joel.goldstick at gmail.com
Fri Apr 20 18:27:54 CEST 2012


On Fri, Apr 20, 2012 at 11:32 AM, Surya K <suryak at live.com> 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(). 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...
>
>
> I java it really works well.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
class MyClass(object):
    def foo(self):
        print "I am foo"
    def bar(self):
        print "I am bar"
        self.foo()

my_instance = MyClass()
my_instance.foo()
my_instance.bar()



-- 
Joel Goldstick


More information about the Tutor mailing list