If you want to directly call a method without instantiating, you can use the staticmethod decorator. Please note that when using the static method
no
self class Ape(object): def __init__(self): print 'ooook' @staticmethod def say(s): print s def main(): Ape.say('eeek') if __name__ == '__main__': main()
Compare with class methods where class is the first parameter instead of instance
class Ape(object): def __init__(self): print 'ooook' @classmethod def say(cls, s): print "the class is:", cls print s def main(): Ape.say('eeek') if __name__ == '__main__': main()
John la rooy
source share